shell script array length

Posted by Dipro Sen on Stack Overflow See other posts from Stack Overflow or by Dipro Sen
Published on 2012-12-14T16:44:44Z Indexed on 2012/12/14 17:03 UTC
Read the original article Hit count: 221

Filed under:
|

I assume arguments to my shell scripts willbe ./x.sh subject N file1 file2 fileN So I am splicing argv from 3 till end candidates=${@:3}

now I want to check whether length of candidates is same as given N I am trying with echo $((${#candidates[@]})) which is always returning 1.

I can do echo "$#-2" | bc but, I shouldn't I be able to get array size ?

I can use bc to do integer comparison. but I've to know the size of `candidates array which I am not getting properly.

© Stack Overflow or respective owner

Related posts about arrays

Related posts about shell