There is a better way...
I'm really surprised at how long this question has gone without a good answer. It may be that the specific version of qsub
wasn't specified. qsub
exists in at least Torque and also Sun Grid Engine, maybe other schedulers. So, it's important to know which you're using. I'll talk about a few here:
TORQUE: qsub -F <arguments> command
man page
Here's an example of how I normally use it. Starting with this example script which just echoes any arguments passed to it:
$ cat testArgs.pbs
#!/usr/bin/env bash
echo $@
I would submit the job like this:
$ qsub -F "--here are the --args" testArgs.pbs
3883919.pnap-mgt1.cm.cluster
And this is what the output file looks like after it runs:
$ cat testArgs.pbs.o3883919
--here are the --args
Sun Grid Engine: qsub command [ command_args ]
man page
You just add the arguments after the command, same as you would when executing in the shell. I don't have SGE running anywhere, so no example for this one. But it's the same with Slurm, which is below
Slurm: sbatch command [ command_args ]
man page
Here I submit the same script I used with the Torque example above:
$ sbatch testArgs.sh what the heck
Submitted batch job 104331
And the results:
$ cat slurm-104331.out
what the heck
Exporting environment variables != passing arguments
Exporting environment variables is very different from passing arguments to a command.
Here is a good discussion on the differences.
The qsub
answers above all recommend -v
. To be clear, -v
exports environment variables, -F
passes arguments to the command.
I generally prefer to parameterize my scripts by allowing for arguments. In fact, I would say it's much more common to use scripts like this process_data.sh --threads 8
than doing something like export THREADS=8; process_data.sh
.
qsub
?qsub 'script.sh -r firstparam -s secondparam'
I have no idea if that works in this case. – Shahqsub
; are you referring to this one? – Fugate