Question

In BASH,

I should note that the variables $Lambda0_List etc, are read from an input file earlier in the code.

PARAM_ARRAY=("Lambda0" "N" "M" "Sigma")

for i in "${PARAM_ARRAY[@]}"

do

 List="$i"_List

 Vary="$i"_Vary

 Use_Range="$i"_Use_Range

 Initial_Str="$i"_Initial

 Final_Str="$i"_Final

 Step_Str="$i"_Step

 Initial=${!Initial_Str}

 Step=${!Step_Str}

 Final=${!Final_Str}

 if [ "${!Vary}" ==  "T" ] 

 then

  if [ "${!Use_Range}" == "T" ]

  then 

   eval "$List=(`seq $Initial $Step $Final `)"

   echo "$i : vary, use_range" 

  else

   echo "$i: vary, use list"

  fi

 fi

done

Throws a syntax error

syntax error near unexpected token `('

Normally I'm able to interpret the error and find a solution, but I don't understand why the "(" is an unexpected token.

edit:

I've noticed that this line works if I run it in shell, but not in my script,

edit:

Fiddling around with the problematic line, I found that I get a syntax error even when its commented out!

/test.sh: line 266: syntax error near unexpected token `('

./test.sh: line 266: ######## eval "$List=(seq $Initial $Step $Final `)"'

Was it helpful?

Solution 2

After sifting through some earlier code, I fixed some issue with ' vs ", and this error stopped coming. I'm new to BASH so I didn't expect that an error message with ')' to be caused by a quote 100 lines above.

OTHER TIPS

After !Final you have a ) instead of a }

why dont use elif or case ?

eval "$List=(seq $Initial $Step $Final)"

instead of

eval "${List=(seq $Initial $Step $Final)}" or eval "${List=seq $Initial $Step $Final}"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top