`#!/bin/bash -l` 中的 `-l` 与使用 `#SBATCH –get-user-env=L` 有何不同?

huangapple go评论119阅读模式
英文:

How is the `-l` in the header `#!/bin/bash -l` different from using #SBATCH --get-user-env=L?

问题

The -l flag in this job file refers to executing as if it was in the login node right? Meaning that it will first read ~/.bash_profile. How is this different from using #SBATCH --get-user-env=L?

这个作业文件中的-l标志指的是以登录节点的方式执行,对吗?这意味着它将首先读取~/.bash_profile。这与使用#SBATCH --get-user-env=L有何不同?

Will the latter flag only read environment variables and not the rest from ~/.bash_profile?

后者的标志只会读取环境变量,而不会读取~/.bash_profile中的其他内容吗?

Not sure whether is it better to use one or the other.
Also don't know if --export NONE will override both of these options.

不确定使用其中一个是更好的,也不知道--export NONE是否会覆盖这两个选项。

英文:

The -l flag in this job file refers to executing as if it was in the login node right? Meaning that it will first read ~/.bash_profile. How is this different from using #SBATCH --get-user-env=L?

Will the latter flag only read environment variables and not the rest from ~/.bash_profile?

Not sure whether is it better to use one or the other.
Also don't know if --export NONE will override both of these options.

#!/bin/bash -l

#SBATCH --account project_id 
#SBATCH --mail-type ALL     
#SBATCH --chdir /scratch/<your_username>/
#SBATCH --job-name my_code 
#SBATCH --output my_code.out
#SBATCH --partition cpu
#SBATCH --nodes 1 
#SBATCH --ntasks 1 
#SBATCH --cpus-per-task 8 
#SBATCH --mem 10G 
#SBATCH --time 00:30:00 
#SBATCH --export NONE
#SBATCH --get-user-env=L

答案1

得分: 2

经过查看文档,似乎它们执行相同的操作。

但最终的行为取决于Slurm如何执行您的脚本。您可能知道有两种不同的方式可以执行Bash脚本:

./script.sh
bash ./script.sh

如果Slurm执行的相当于前者,那意味着您的-l标志会生效,并且脚本将由Bash登录shell运行。在这种情况下,Linux内核查看文件,查看shebang,并带有-l参数运行Bash。

然而,如果Slurm执行的相当于后者,那意味着您的-l标志没有效果。在这种情况下,Bash读取文件,并忽略第一行,因为它是注释。

因此,我建议设置#SBATCH --get-user-env=L,因为这是Slurm保证脚本将在登录shell中可执行的方式。添加-l可能没有效果(要确保,人们必须查看源代码,即使这样,由于它是实现细节,行为也可能会发生变化)。

英文:

After looking at the docs, it seems like they do the same thing.

But in the end, the behavior depends on how Slurm executes your script. You may be aware that there are two different ways you can execute a Bash script yourself:

./script.sh
bash ./script.sh

If Slurm does the equivalent of the former, then that means that your -l flag takes effect and the script is ran by a Bash login shell. In this case, the Linux kernel looks at the file, looks at the shebang, and runs Bash with the -l argument.

However, if Slurm does the equivalent of the latter, then that means your -l flag has no effect. In this case, Bash reads the file, and ignores the first line because it is a comment.

Therefore, I would recommend setting #SBATCH --get-user-env=L, because that is a guarantee by Slum that the script will executable in a login shell. Adding -l may not have an effect (one would have to look at the source code to be sure, and even then, it is possible the behavior can change since it is an implementation detail).

huangapple
  • 本文由 发表于 2023年7月18日 00:53:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706602.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定