bash 用于在 for 循环中为变量赋值的脚本
bash script to assign value to a variable in for loop
我正在尝试将每个批处理作业提交到不同的目录,即 .test1/、.test2/、.test3/。因此,我遍历 ./test* 目录并设置变量 $SLURM_SUBMIT_DIR,它控制我提交作业的目录。
#!/bin/bash -l
# script.sh
DIRS="./test*/"
for dir in $DIRS
do
export $SLURM_SUBMIT_DIR =$dir
echo $dir
sbatch submitfile
done
结果出来了:
script.sh: line 9: export: `=./test1scan/': not a valid identifier
./test1scan/
Submitted batch job 312892
script.sh: line 9: export: `=./test2scan/': not a valid identifier
./test2scan/
Submitted batch job 312893
script.sh: line 9: export: `=./test3scan/': not a valid identifier
./test3scan/
Submitted batch job 312894
已编辑:
感谢 Chepner,错误消失了。但是,作业是在我 运行 这个 bash 脚本所在的目录中提交的。有什么方法可以在不同的目录中提交每个作业?
您不能在 export
:
的参数中等号后加上 space
export "$SLURM_SUBMIT_DIR=$dir"
我正在尝试将每个批处理作业提交到不同的目录,即 .test1/、.test2/、.test3/。因此,我遍历 ./test* 目录并设置变量 $SLURM_SUBMIT_DIR,它控制我提交作业的目录。
#!/bin/bash -l
# script.sh
DIRS="./test*/"
for dir in $DIRS
do
export $SLURM_SUBMIT_DIR =$dir
echo $dir
sbatch submitfile
done
结果出来了:
script.sh: line 9: export: `=./test1scan/': not a valid identifier
./test1scan/
Submitted batch job 312892
script.sh: line 9: export: `=./test2scan/': not a valid identifier
./test2scan/
Submitted batch job 312893
script.sh: line 9: export: `=./test3scan/': not a valid identifier
./test3scan/
Submitted batch job 312894
已编辑: 感谢 Chepner,错误消失了。但是,作业是在我 运行 这个 bash 脚本所在的目录中提交的。有什么方法可以在不同的目录中提交每个作业?
您不能在 export
:
export "$SLURM_SUBMIT_DIR=$dir"