Bash的启动文件

启动文件也是一种脚本,不过它是在Bash在启动之初就执行它的。不同的启动方式使用的启动文件也有不同。

1. 作为交互的登录脚本环境
“交互的”是指你可以再这个环境下输入命令。而所谓的登录,则是需要你输入用户名和密码之后,才能启动shell环境。比如你使用的tty0~tty6等几个terminal,就是需要登入的shell环境。
这种启动方式下,bash会读取下列配置文件。
/etc/profile
~/.bash_profile,~/.bash_login,~/.profile
~/.bash_logot 登出时执行

如果配置文件存在,但是没有读取权限,bash会打印出错误信息来。如果文件本就不存在,bash 会查找下一个配置文件。
通常PATH等环境变量就在/etc/profile文件中初始定义,然后我们会在~/.profile中添加我们订制的PATH。

2. 作为交互的不需要登录脚本环境
不需要登录以为着你只需要打开环境->使用就可以了。比如,你通过桌面图标打开terminal,或者是从菜单打开terminal等,这些都是不需要登陆的shell。
这种方式下,bash会去读取:
~/.bashrc
这个文件在前一种方式里面,在~/.bash_profile(或是~/.profile)中会被调用,这里是debian自动生成~/.profile的内容。

3. 非交互的调用
所有的脚本文件都是非交互的执行。这些脚本都是被设计来执行特定的任务,也不会去执行那些它没涉及到的操作,所以运行环境通常都是特定的。
这种情况下,bash会去读取:
BASH_ENV定义的文件
在这种情况下,PATH并不会被应用,所以,如果我们想执行某个应用,我们必须得给出它的full path以及full name。

4. 作为shell command被调用
遵从POSIX的传统,bash会尽量表现的和传统的Bourne sh一样。
这时,下列文件会被读取:
/etc/profile
~/.profile

Differences in interactive mode:

Bash reads startup files.

Job control enabled by default.

Prompts are set, PS2 is enabled for multi-line commands, it is usually set to “>”. This is also the prompt you get when the shell thinks you entered an unfinished command, for instance when you forget quotes, command structures that cannot be left out, etc.

Commands are by default read from the command line using readline.

Bash interprets the shell option ignoreeof instead of exiting immediately upon receiving EOF (End Of File).

Command history and history expansion are enabled by default. History is saved in the file pointed to by HISTFILE when the shell exits. By default, HISTFILE points to ~/.bash_history.

Alias expansion is enabled.

In the absence of traps, the SIGTERM signal is ignored.

In the absence of traps, SIGINT is caught and handled. Thus, typing Ctrl+C, for example, will not quit your interactive shell.

Sending SIGHUP signals to all jobs on exit is configured with the huponexit option.

Commands are executed upon read.

Bash checks for mail periodically.

Bash can be configured to exit when it encounters unreferenced variables. In interactive mode this behavior is disabled.

When shell built-in commands encounter redirection errors, this will not cause the shell to exit.

Special built-ins returning errors when used in POSIX mode don't cause the shell to exit. The built-in commands are listed in the section called “Shell built-in commands”.

Failure of exec will not exit the shell.

Parser syntax errors don't cause the shell to exit.

Simple spell check for the arguments to the cd built-in is enabled by default.

Automatic exit after the length of time specified in the TMOUT variable has passed, is enabled.

最新文章

  1. .NET4.5 WFP中用WebBrowser获取/操作网页html代码
  2. centos7安装redis
  3. 图片大小的模式UIViewContentMode
  4. 我看的公开课系列--《TED:对无知的追求》 by stuart firestein
  5. 初级jQuery的使用
  6. 响应式布局中重要的meta标签设置.适用于手机浏览器兼容性设置
  7. Windows上Python3.5安装Scrapy(lxml)
  8. arch Failed to load module "intel"
  9. Mybash的实现
  10. IOS 选择会员资格
  11. XLSReadWriteII5使用参考
  12. SQL Server实现读写分离提高系统并发
  13. 二进制安装 kubernetes 1.12(一) - 安装 ETCD
  14. CRM模块
  15. 转载:Java中的字符串常量池详细介绍
  16. iptables之四表五链
  17. Status bar and navigation bar appear over my view's bounds in iOS 7
  18. cocoside 编译错误可能问题
  19. item2
  20. fb远程连接服务器调试,碉堡了

热门文章

  1. JavaScript中正则表达式test()、exec()、match() 方法区别
  2. TextBox自定义控件
  3. SQL基础之XML
  4. Nginx+Varnish 实现动静分离,为服务器分流,降低服务器负载
  5. 1111MySQL配置参数详解
  6. oracle主键自增
  7. org.apache.commons.lang3.ArrayUtils 学习笔记
  8. bzoj1503
  9. HTTP协议学习---(七)代理
  10. win10下安装Ubuntu出现win10无法进入的情况