Argument passing in .sh scripts

I have a shell script foo.sh which is qsub with content:

  #!/bin/bash -l #$ -S /bin/bash #$ -N $2 echo $1 

I would like to pass two arguments. If I call qsub foo.sh ab, the first argument will be correctly processed and repeated on the command line as "a". However, I do not know how to pass an argument in the second case, starting with "# $ -N". In this case, $ 2 is not evaluated as 'b', but actually '$ 2'. Help would be greatly appreciated.

+6
source share
2 answers

No, you can’t. # At the beginning of the line, it makes $ 2 not be replaced by the script argument. The way to do what you are trying to do is

 qsub foo.sh -N <name> 
+1
source

It works for me.

I don't know what the -N command means, but

 #!/bin/bash -l #$ -S /bin/bash #$ -N $2 echo $1 echo $2 

calling sh foo.sh ab quickly echoes

 a b 
+2
source

Source: https://habr.com/ru/post/905479/


All Articles