0

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.

Bram Vanroy
  • 183
  • 1
  • 11
  • 1
    If you're on Bash, that unquoted `INFO=$info` will get word-split, likely making `is`, `some` etc. taken as filenames. The result should be quite different with and without the quotes. – ilkkachu Jul 05 '23 at 05:47
  • 1
    Duplicate of https://stackoverflow.com/q/76616176/7552 – glenn jackman Jul 05 '23 at 11:42
  • @glennjackman Yes, I made that explicit at the start. – Bram Vanroy Jul 05 '23 at 11:49
  • In that case, please delete the instance over at stackoverflow. Cross-posting is strongly discouraged in the SE network and will lead to close-votes. – AdminBee Jul 05 '23 at 13:03
  • At the very least, link to it so people who want to answer here can see what has already been talked about there. – glenn jackman Jul 05 '23 at 15:38

2 Answers2

1

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
Hauke Laging
  • 88,146
  • 18
  • 125
  • 174
  • 2
    That cannot possible work without `export INFO`. – Kaz Jul 05 '23 at 01:20
  • 2
    @Kaz That is correct - but only for the first case. The second one does not need (does not even work with) export. Thanks for noticing and mentioning. – Hauke Laging Jul 05 '23 at 06:14
-4
qsub -v INFO="$info" script.pbs
Ipor Sircer
  • 14,376
  • 1
  • 27
  • 34