I have a array with a few string values, and I correctly can out it in console:
for element in "${answers[@]}"
do echo $element
done
out:
1
2
5
But I need do some command for each value in array:
For example this implementation does not execute any action:
for element in "${answers[@]}";
do
# switch $element {
case $element in
1)
echo "install app 1";;
2)
echo "install app 2";;
3)
echo "install app 3 ";;
esac
done
In follow attempt:
for element in "${answers[@]}";
do
switch $element {
case "1": echo "install app 1";;
case "2": echo "install app 2";;
case "3": echo "install app 3";;
}
done
I have exception:
./prepare_2.0.sh: line 15: syntax error near unexpected token
echo' ./prepare_2.0.sh: line 15:
case "1": echo "install app 1";;'
How to correctly implement this logic?
You splits string value, but in first attempt you not use it. Just change '1)' to '"1")'
for element in "${answers[@]}"; do