我正在尝试在 bash 中编写一个脚本,该脚本从七个变量“构建”一个数组。例如:
a=7
b=3
c=5
....
declare -a elem_arr=( "$a" "$b" "$c"..."$g" )
echo "$elem_arr[1]" # this doesn't echo anything.
if [ "$elem_arr[1]" -ne "$elem_arr[2] ]; then
echo "$elem_arr[1] is not equal to $elem_arr[2]"
fi
这似乎不起作用。是否可以以这种方式构造数组?