Artificial intelligent assistant

Bash array appending element issue I have an array declare -a her=("ger" "blr" "tyg" "") for i in "${her[@]}"; do echo $i done I get ger blr tyg But when I try and append to an array I get one long string with no spaces declare -a you #without quotes and with quotes #' " same result for i in {"fgt","fe","ger"}; do you+=${i} done for i in "${you[@]}"; do $i done Fgtfeger Any insight on whats happening ? Kinda makes them not as useful

## Use Array Compound Assignment Syntax; Otherwise Use Length as Index

You have to append to an array using either the compound assignment syntax (e.g. `foo=("elem1" ...)` or an array index.

### Array Compound Assignment Syntax

The form with parentheses allows you to insert one or more elements at a time, and is (arguably) easier to read. For example:


# start with a clean slate
unset you

for i in "fgt" "fe" "ger"; do
you+=("$i")
done

printf "%s\
" "${you[@]}"


This yields the values you'd expect:

>
> fgt
> fe
> ger
>

### Insert at Index _Length_

You can get similar results by assigning to an index. For example:


unset you
for i in "fgt" "fe" "ger"; do
you[${#you[@]}]="$i"
done
printf "%s\
" "${you[@]}"


This second example works because Bash arrays are zero-indexed, so the _length_ of the array is also the next available index that should be assigned when appending.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 164d4ea3b85b9892ae1979f44fab1212