bash: non-login shell和login shell的区别
2013-06-08 00:00
323 查看
详细介绍可以察看info bash中的INVOCATION部分。此处仅作简要总结。
The difference between a login shell and a non-login shell (info bash)
login shell
*) interactive login shell
*) non-interactive shell with --login option
*) behavior
*) it reads and executes /etc/profile if exists
*) it looks for ~/.bash_profile, ~/.bash_login and ~/.profile, in that
order and reads and executes the first one found
non-login shell
*) interactive non-login shell
it reads and executes /etc/bash.bashrc and ~/.bashrc
*) non-interactive non-login shell
it first executes the following command before running the script
if [ -n "$BASH_ENV" ]; then . $BASH_ENV; fi
举例说明下有点“奇怪”的non-interactive non-login shell的行为(这是我们通常执行脚本时的默认模式)。
chenqi@chenqi-Vostro-2420:~/tests$ cat test.sh
#!/bin/sh
echo hello world
chenqi@chenqi-Vostro-2420:~/tests$ echo $BASH_ENV
chenqi@chenqi-Vostro-2420:~/tests$ ./test.sh
hello world
chenqi@chenqi-Vostro-2420:~/tests$ export BASH_ENV=~/tests/test.sh
chenqi@chenqi-Vostro-2420:~/tests$ echo $BASH_ENV
/home/chenqi/tests/test.sh
chenqi@chenqi-Vostro-2420:~/tests$ ./test.sh
hello world
chenqi@chenqi-Vostro-2420:~/tests$ bash test.sh
hello world
hello world
将test.sh的默认执行shell改成/bin/bash,有如下结果:
chenqi@chenqi-Vostro-2420:~/tests$ cat test.sh
#!/bin/bash
echo hello world
chenqi@chenqi-Vostro-2420:~/tests$ ./test.sh
hello world
hello world
The difference between a login shell and a non-login shell (info bash)
login shell
*) interactive login shell
*) non-interactive shell with --login option
*) behavior
*) it reads and executes /etc/profile if exists
*) it looks for ~/.bash_profile, ~/.bash_login and ~/.profile, in that
order and reads and executes the first one found
non-login shell
*) interactive non-login shell
it reads and executes /etc/bash.bashrc and ~/.bashrc
*) non-interactive non-login shell
it first executes the following command before running the script
if [ -n "$BASH_ENV" ]; then . $BASH_ENV; fi
举例说明下有点“奇怪”的non-interactive non-login shell的行为(这是我们通常执行脚本时的默认模式)。
chenqi@chenqi-Vostro-2420:~/tests$ cat test.sh
#!/bin/sh
echo hello world
chenqi@chenqi-Vostro-2420:~/tests$ echo $BASH_ENV
chenqi@chenqi-Vostro-2420:~/tests$ ./test.sh
hello world
chenqi@chenqi-Vostro-2420:~/tests$ export BASH_ENV=~/tests/test.sh
chenqi@chenqi-Vostro-2420:~/tests$ echo $BASH_ENV
/home/chenqi/tests/test.sh
chenqi@chenqi-Vostro-2420:~/tests$ ./test.sh
hello world
chenqi@chenqi-Vostro-2420:~/tests$ bash test.sh
hello world
hello world
将test.sh的默认执行shell改成/bin/bash,有如下结果:
chenqi@chenqi-Vostro-2420:~/tests$ cat test.sh
#!/bin/bash
echo hello world
chenqi@chenqi-Vostro-2420:~/tests$ ./test.sh
hello world
hello world
相关文章推荐
- login shell 和 non-login shell 的区别
- linux系统中login shell与non-login shell的区别
- login shell和non-login shell的区别:
- non-login shell 与login shell的区别
- /etc/profile与/etc/bashrc、交互式与非交互式、login与non-login shell的区别
- login shell 和 non-login shell 的区别
- Linux系统login shell和non-login shell区别与影响
- 环境配置文件: login, non-login shell, /etc/profile, ~/.bash_profile, source, ~/.bashrc
- login shell与non-login shell的区别
- Linux下Bash的操作环境相关,issue,motd,login shell,non-login shell,source,stty,set
- login shell与non-login shell的区别
- login shell 和non-login shell的区别
- 【linux学习笔记】bash学习之login shell与non-login shell(source命令)
- login-shell和non login-shell区别 & bash配置文件实验报告
- login shell 与non-login shell区别
- sh/bash/csh/Tcsh/ksh/pdksh等shell本质区别
- ubuntu下shell脚本运行异常:bash和dash的区别
- linux bash shell中,单引号、 双引号,反引号(``)的区别及各种括号的区别
- Shell: sh,bash,csh,tcsh等shell的区别
- Login and non-login shell