I want to check if the length of a bash array is equal to a bash variable (int) or not. My current code looks like this:
if [ "${#selected_columns}" -eq "${number_of_columns}" ]; then
echo "They are equal!"
fi
This returns false since the echo statement is never run. However, doing this produces 4 for both of them:
echo "${#selected_columns[@]}"
echo "${number_of_columns}"
What's wrong here? Has it something to do with string versus int?
[@]in the first example?if [ "${#selected_columns[@]}" -eq "${number_of_columns}" ]; then