Variable expansion in comments
Variable expansion happens in shell memory, it doesn't affect the file. Therefore, it doesn't matter what bash expands.
Instead, you can probably generate the script to be run on the fly, with everything expanded in place:
cat << EOF | qsub [options] -#$ -o run_$1.outcmdsEOF
To be a bit more SGE specific than the accepted answer, just redirect the standard output of qsub
and parse the job id. You can then use this to alter the job name via qalter
.
Here's a sample of a script I used to submit and modify jobs like this.
for a in $args; do qsub submission_script $a 1> job.txt jid=$(cat job.txt | tr -dc '0-9' | cut -c -6) qalter $jid -N $a done
I'm certain that there are more idiomatic ways to do this, but this is a first go.
This approach allows submission_script
to have it's own arguments. It also allows you to programmatically alter other job characteristics, not just the name.
I am also using the qsub
command in SGE to generate different output or error logs. For example, if I would like to include the TASK_ID
in the script, instead of doing
#$ -o run_${TASK_ID}.out
Write it without the paretheses will do the trick:
#$ -o run_$TASK_ID.out