bashshellpbsqsubvariable-expansion

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


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.


Solution

  • 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