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.
The way you are assigning
candidatesis not making an array. To make it an array, do:In bash, you can get the number of elements in the array with
${#candidates[*]}. To check if that is equal to$2, just do: