linux - #!/bin/bash --login vs #!/bin/bash

标签 linux macos bash shell jenkins

我在寻找使用 Jenkins 运行 Appium 的脚本时阅读了以下脚本

#!/bin/bash --login

killall -9 "iPhone Simulator" &> /dev/null
killall -9 node &> /dev/null
killall -9 instruments &> /dev/null
...

我不明白为什么脚本的第一行需要在这里传递一个--login选项。我已经阅读了手册页,但仍然有些困惑。

我从手册页中得到的是传递 --login 以使脚本被称为 login shell 而不是 interactive shell。 interactive shell 是用户可以与 shell 交互的 shell,比如用键盘输入一些东西。但是什么是 login shell?我检查了它说 login shell 将加载 ~/.bash_profile 的手册页,但是如果通过 Mac OSX 的 Terminal.app 打开终端,它也会加载 ~/.bash_profile 并且我能够与 shell 交互,对吗?那么,我打开的shell既是login shell又是interactive shell

最佳答案

主要区别在于登录 shell 在启动时会执行您的配置文件。从手册页:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.

关于linux - #!/bin/bash --login vs #!/bin/bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25677790/

相关文章:

c++ - 确保程序在终端中

javascript - PWA 能否自动将自身添加到 macOS 应用程序 Dock,或在登录时自动启动?

linux - Shell/bash 中的模式和正则表达式

python - 按行计算匹配某些规则的两个字符之间的大文件中的总字节数

php - PHP SQL 查询的案例与 MySQL 数据库的案例不同。不能使用 lower_case_table_names = 1

java - 如何调用 Linux shell 并为其设置 PATH?

c++ - 黄金链接器 : specify alignment of sections

c++ - #include <FreeImage.h> 未找到

python - OS X 10.10.3 launchctl 权限被拒绝

bash which OR operator to use - 管道 v 双管道