for loop over character array gives unexpected "("
Solution 1:
the
( unexpected
error indicates you're calling your script likesh scriptname
instead ofbash scriptname
or, preferably,chmod 755 scriptname; ./scriptname
-
Dynamic array names are hard to work with in bash. You require a temporary variable to use with indirect expansion.
for SCANPOSITION in "${POS[@]}" do tmp="ZSPOS_${SCANPOSITION}[@]" for ZEITSCHNITT in "${!tmp}" # note the "!" do echo "Timeslice $ZEITSCHNITT in Position $SCANPOSITION !" done done
You should always quote your
"$variables"
unless you know exactly why you want to leave the quotes off.Also, get out of the habit of using
ALL_CAPS_VARS
-- some day you will accidentally usePATH
and then wonder why your script is broken