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

After seeing the reactions on Stack Overflow on this question and an unfamiliarity with qsub, I believe thqt U&L is better suited for this question.

In qsub, we can pass environment variables (a comma-separated list of envar=value pairs) 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 which always end up incorrectly when they are passed (backslash gets removed).

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.

Asked By: Bram Vanroy

||
qsub -v INFO="$info" script.pbs
Answered By: Ipor Sircer

You can avoid this problem by giving only the variable name on the command line (which is visible to the command):

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

or

INFO="This is some info, and here is some more!" qsub -v INFO script.pbs
Answered By: Hauke Laging