my_array=(apple banana "Fruit Basket" orange) echo ${my_array[3]} # orange - note that curly brackets are needed # adding another array element my_array[4]="carrot" # value assignment without a $ and curly brackets echo ${#my_array[@]} # 5 echo ${my_array[${#my_array[@]}-1]} # carrot
#!/bin/bash NAMES=( John Eric Jessica ) # write your code here NUMBERS=() STRINGS=() NumberOfNames=0 second_name='Vladimir'
Expected Output
1 2 3 4
1 2 3 hello world The number of names listed in the NAMES array: 3 The second name on the NAMES list is: Eric
Solution
1 2 3 4 5 6 7 8 9 10 11
#!/bin/bash NAMES=( John Eric Jessica ) # write your code here NUMBERS=( 1 2 3 ) STRINGS=( "hello" "world" ) NumberOfNames=${#NAMES[@]} second_name=${NAMES[1]} echo ${NUMBERS[@]} echo ${STRINGS[@]} echo "The number of names listed in the NAMES array: $NumberOfNames" echo "The second name on the NAMES list is:" ${second_name}