0

I am trying to embed a cdo line in a shell script with variables. As a command line it works, but not in a script. This is the cdo line:

cdo -expr,'T_mask=((T > 200 ))' file_in.nc file_out.nc

In the shell script I want to run it for three different temperature thresholds, e.g. 200, 250, 300.

This is the code:

T_string='T_mask=((T > '
fileA='file_in.nc'
fileB='file_out.nc'
for T_var in 200 250 300; do
    cdo_string="'$T_string$T_var))'"
    cdo  -expr,$cdo_string  $fileA $fileB
done

I get the following error:

cdo (Abort): Unprocessed Input, could not process all Operators/Files

What did I miss? Are the hyphens set right?

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
Zeusuez
  • 3
  • 2

1 Answers1

2

The $T_string variable seems needless. When using similarly named shell variables, always use curly braces.

Try this:

fileA='file_in.nc'
fileB='file_out.nc'
for T_var in 200 250 300; do
    cdo  -expr,'T_mask=((T > '"${T_var}"'))'  "${fileA}" "${fileB}"
done
agc
  • 7,973
  • 2
  • 29
  • 50