for loop over character array gives unexpected "("

Solution 1:

  1. the ( unexpected error indicates you're calling your script like sh scriptname instead of bash scriptname or, preferably, chmod 755 scriptname; ./scriptname

  2. 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
    
  3. You should always quote your "$variables" unless you know exactly why you want to leave the quotes off.

  4. Also, get out of the habit of using ALL_CAPS_VARS -- some day you will accidentally use PATH and then wonder why your script is broken