There is an array that is being fed into a for each
loop that has a case
statement within. The array is being generated through a read
from CSV.
read -p "Path to CSV file with field data:" csvFile
while IFS=',' read -ra array; do
ar1+=("${array[0]}") # Field Name
ar2+=("${array[1]}") # Field ID
ar3+=("${array[2]}") # Field Type
done < $csvFile
arLength=${#ar1[@]}
for (( i=0; i<$arLength; i++ )); do
case ${ar3[$i]} in
Drop-down)
echo "foo"
;;
Multi-select)
echo "bar"
;;
*)
echo "none"
;;
esac
done
Values possible in ar3
include Multi-select, Multi-line, Drop-down, Text, Date, Numeric
The issue is that the values in the ar3
array are not being evaluated properly, and instead everything is receiving the else
treatment (echo "none"). I have tried the following:
- Case statement compares on one line
Drop-down|Multi-select)
- Various quotes (single and double) around either the array variable, options, or both
- Escaping hyphens
- Evaluating against another option w/o special characters
Not sure what I have wrong here to make it not evaluate properly.