I am new to shell scripting and I am trying a simple task of getting the length of a sequence of numbers generated using seq
.
With the help of a related post here: How to find the array length in unix shell? I was able to do this -
a=(1 2 3 4 5)
echo ${#a[@]} #length of a
5 #length of a = 5 (This is fine !!)
However when I try to do a similar thing using seq
..
b=$(seq 1 1 10)
echo $b
1 2 3 4 5 6 7 8 9 10
echo ${#b[@]}
1 #the length of b is 1, while I expect it to be 10
Why does this happen ? Are the variable types a and b different? is b not an array ?
I am sure I am missing something very trivial here, help is greatly appreciated.
Thanks
Ashwin