문제

I have the following shell script named dump.sh

#!/bin/sh
#$ -cwd
#$ -j y
#module load gcc octave
octave --eval "dumpoct($Nlay, $prefix);"

This script loads the octave module and then evaluates the following octave function, which simply displays the two input arguments

function dumpoct(arg1,arg2)
display(arg1)
display(arg2)

When I submit the shell script as follows, it works (passing two numbers as arguments)

qsub -v Nlay=10,prefix=40 dump.sh

However when I submit it with one number one string argument as follows:

qsub -v Nlay=10,prefix="qwerty" dump.sh

I get an error

error: `qwerty' undefined near line 0 column 13
error: evaluating argument list element number 2

I have also tried the following and I get the same errors

qsub -v Nlay=10,prefix='qwerty' dump.sh
qsub -v Nlay=10,prefix=qwerty dump.sh

Any idea how I can do that?

Thank you

Giorgos

도움이 되었습니까?

해결책

I think this is a bash interpreter issue, in that it basically removes the quotes. Try this:

qsub -v Nlay=10,prefix=\"qwerty\" dump.sh

The backslashes prevent the quotation marks from being interpreted as instructions for the bash interpreter.

Note: it may not completely solve the problem, due to bash itself being used in dump.sh. You may also need to pass the backslashes themselves... which makes it look a bit bulky, like this:

qsub -v Nlay=10,prefix=\\\"qwerty\\\" dump.sh

Which would then appear in dump.sh as \"qwerty\", which would then be interpreted by bash and be passed to octave as "qwerty". Not sure if there's a more sleek solution.

There's a more sleek solution, although only slightly so. It's like this:

qsub -v Nlay=10,prefix='\"qwerty\"' dump.sh

Single quote will make it pass the backslashes, but unfortunately you can't use two single quotes - it won't pass ''qwerty'' correctly.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top