我在寻找使用 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/