Array - Create an simple array in linux terminal
In this article we can learn how to declare/define/create an array in linux commandline terminal.
method1) using direct index values:
usage:
1 array[value]="element"
examples:
1 arrayNames[0]="btc"
2 arrayNames[1]="usdt"
3 arrayNames[2]="eth"
4 echo "${arrayNames[@]}"
method2) using parentheses:
usage:
1 array=( element1 element2 element3. . . elementN )
2
examples:
1 arrayNames=( btc usdt eth eos )
2 echo ${arrayNames[0]}
method3) using inside the parantheses:
usage:
1 array=( [XX]=<value> [XX]=<value> . . . )
examples:
1 arrayNames=( [0]="btc" [1]="usdt [3]="eos" [2]="eth" )
2 echo ${arrayNames[2]}
method4) using read user inputs to an array using read command:
1 read -a arrayNames < <(echo "btc usdt eos eth")
2 echo "${arrayNames[@]}"
or
1 read -a arraynames
2 #then input the values