Search code examples
bashslurm

How to pass two variables in bash to a python script


I am trying to pass an array index and filename to a python script bu tI just can't get it to work:

#!/bin/bash
#SBATCH --job-name=test
#SBATCH --output=Test.txt
#SBATCH --array=0-1

for Folder in ~/users/**/**/T*A*
do
    File= basename ${Folder}
    python test.py ${SLURM_ARRAY_TASK_ID} ${File}
done

I want to pass the SLURM_ARRAY_TASK_ID and filename to the python script but it doesn't pass the filename in.

SOLUTION: Using spellcheck.net The code should be :

#!/bin/bash
#SBATCH --job-name=test
#SBATCH --output=Test.txt
#SBATCH --array=0-1

for Folder in ~/users/**/**/T*A*
do
    File=$(basename "${Folder}")
    python test.py "${SLURM_ARRAY_TASK_ID}" "${File}"
done

Solution

  • If you enclose the basename command inside $() and enclose the variables in double quotes to ensure that they are passed as separate arguments, then it should work.