How to Pass Parameters from QSub to Bash Script?

社会主义新天地 提交于 2019-11-30 18:05:55

Using PBSPro or SGE, arguments can simply be placed after the script name as may seem intuitive.

qsub example.sh hello world

In Torque, command line arguments can be submitted using the -F option. Your example.sh will look something like this:

#!/bin/bash echo "$1 $2"

and your command like so:

qsub -F "hello world" example.sh

Alternatively, environment variables can be set using -v with a comma-separated list of variables.

#!/bin/bash echo "$FOO $BAR"

and your command like so:

qsub -v FOO="hello",BAR="world" example.sh

(This may be better phrased as a comment on @William Hay's answer, but I don't have the reputation to do so.)

Not sure which batch scheduler you are using but on PBSPro or SGE then submitting with qsub example.sh this is a test should do what you want.

The Torque batch scheduler doesn't (AFAIK) allow passing command line arguments to the script this way. You would need to create a script looking something like this.

#!/bin/bash

echo $FOO

Then submit it with a command like:

qsub -v FOO="This is a test" example.sh
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!