I’ve been attempting to use the --export flag with sbatch to specify per-run environment variables for individual scripts. The function, however, does not seem to be working as it is specified in the SLURM manual for that command.
A minimal example (ran on debug-cpu on Bamboo) is:
script.sh
#!/bin/bash
echo ${A}
echo ${B}
I then, in a terminal with A and B unset, run the following command per the man page:
$ sbatch script.sh --export=A=1,B=2
The expected output is that the file slurm-XXXX.out should contain 1 and 2, but instead the file is empty with no contents.
I have found that running the following command instead will work:
$ export A=1
$ sbatch ./script.sh --export=A=1
but trying to change the value in the --export flag from 1 to another value will retain the original exported value of 1.
The command should work as specified in my first example according to the documentation, allowing me to bind a variable using the export flag only. Am I missing something, or is this a bug?
The issue here is the argument order: you are specifying the flag --export as argument for your script script.sh which is not what you want. You need to do something like the following:
$ sbatch --export=A=1,B=2 script.sh
By the way, are you sure you need to that? By default all the users’s env var are propagated. If you specify a variable to export using --export then no other variables are exported.
Thank you for the response! I was planning on using the env variables to specify certain parameters to the job script that change between simultaneously submitted jobs. I.e SUBJECT=“A” for one and SUBJECT=“B” for another. It seemed like an easy way to approach the problem, though it seems to be difficult in practice.
In the example you provided the issue is that B is still not passed on to the job script environment. A is successfully propagated but B is empty when echoed. Do you have an idea of why that might be?