天天看点

bash 类别简述

本文内容来自man bash。

bash从不同角度看分为两种,一种是是否登录(login),另一种是是否交互式(interactive)。

登录式shell是启动时:

1. 第0个参数以“-”开头

2. 或使用--login选项

交互式shell是启动时:

1. 没有非选项参数除非用使用了-s选项;

2. 并且没有-c选项;

3. 并且input/outptu与terminal相连;

4. 并且用-i选项

两种不同分法的shell有4种组合方式:

1. 交互登录式shell

2. 交互非登录式shell

3. 非交互登录式shell

4. 非交互非登录式shell

(如果相应文件不存在就跳过)

退出时会执行:

在执行脚本时,回去找bash_env这个环境变量,并用这个环境变量的值作为脚本名执行

我的系统是debian,查看相应文件可以看到

一般来说,在~/.profile中会去source ~/.bashrc,也就是说我们平时配置环境是,直接在~/.bashrc中配置即可。

最后说一下如何检测当前shell是否为交互式的

 determine within a startup script whether or not bash isrunning interactively,test the value of the ‘-’ special parameter.it contains<code>i</code> when the shell is interactive. for example: