Pass a variable that contains a comma as a -v option to qsub

178 Views Asked by At

In qsub, we can pass environment variables like so:

info="This is some info"
qsub -v INFO=$info script.pbs

However, this becomes problematic when $info contains a comma.

info="This is some info, and here is some more!"
qsub -v INFO=$info script.pbs

This will trigger an error like so:

ERROR: -v: variable ' and here is some more!' is not set in environment variables.

I have also tried encapsuling info, INFO="$info" leading to the same issue.

How can I pass $info correctly, even if it contains one or more commas? The same question holds with newlines.


Perhaps an interesting observation is that when I echo -e $info I get the output that I expect. The error is triggered in the qsub command specifically.

1

There are 1 best solutions below

0
user1934428 On BEST ANSWER

I just found on the qsub man-page, that there is no documented way for the option -v variable[=value],... to safely place a comma into value. Perhaps there is an undocumented way which you can find out by studying the source code of qsub.

However there is a workaround: If we just specify -v variable without providing a value, it interprets variable as environment variable in the current environment, and uses its value. In your case, this means that you can do a

export INFO="some string, having commas"
qsub -v INFO script.pbs