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.

bash的配置的更多相关文章

  1. 第6天【egrep、bash环境配置及脚本、vim编辑器】

    bash环境配置及脚本(02)_recv bash环境配置及脚本(02)_recv bash环境配置文件: 按生效范围划分,存在两类: 全局配置: /etc/profile /etc/bashrc 个 ...

  2. bash 环境配置及脚本

    bash是 Bourne Again Shell简称 ,从unix系统的sh发展而来 查看当前shellecho $SHELL查看系统支持的shellcat /etc/shells cd /binls ...

  3. 学习bash——环境配置

    一.环境配置文件的重要性 Bash在启动时直接读取这些配置文件,以规划好bash的操作环境. 即使注销bash,我们的设置仍然保存. 二.login shell 通过完整的登录流程取得的bash,称为 ...

  4. git bash 初始化配置

    这里只针对 windows 下,使用git 时的一些初始配置 1. git bash 安装 下载地址: https://git-for-windows.github.io/ 根据提示,一步步安装即可 ...

  5. Git Bash主题配置

    考虑到window的 Vim操作,发现Git Bash自带命令行很好用. Vim写作Markdown真的好用 还不是为了装逼 只是配色很不爽,就找了这个. 不要怕非常简单麻烦,需要2步骤 1- 打开g ...

  6. 在git bash 中配置git用户名和邮箱及查看配置信息

    Administrator@LuoTong- MINGW32 ~ $ git config --global user.name "mrluotong" Administrator ...

  7. Windows 环境下配置 git bash 的 HOME 默认路径

    0.引 在 windows 下安装 git 之后, git 默认的HOME和~路径一般都是C:\Users\用户名,每次得用命令切换到常用的Repository下,此操作重复而没有意义.为了修改默认路 ...

  8. Windows10 Ubuntu bash 配置 LAMP+JDK+Tomcat

    Windows10的Bash省去了装ubuntu虚拟机的麻烦,而且可以直接用Windows下的浏览器去访问了,Exciting有没有,再也不用去忍受日常崩溃的chromium和慢慢的firefox了. ...

  9. CVE: 2014-6271、CVE: 2014-7169 Bash Specially-crafted Environment Variables Code Injection Vulnerability Analysis

    目录 . 漏洞的起因 . 漏洞原理分析 . 漏洞的影响范围 . 漏洞的利用场景 . 漏洞的POC.测试方法 . 漏洞的修复Patch情况 . 如何避免此类漏洞继续出现 1. 漏洞的起因 为了理解这个漏 ...

随机推荐

  1. Linux shell的输入输出

    echo --echo命令可以显示文本行或变量,或者把字符串输入到文件 --echo [option] string -e 解析转义字符 例如:echo -e "nimenhao\nasfd ...

  2. Java应用程序项目的打包与发行(run.bat形式)

    参考: http://www.iteye.com/topic/57312 背景: 以前一直都是在eclipse上面创建应用程序,每次要要运行的时候都要打开eclipse, 直到有个同事叫我帮忙写一个应 ...

  3. c++虚函数注意事项

    >在基类方法声明中使用关键字virtual,可以使该方法在基类及所有的派生类中是虚的 >如果使用指向对象的引用或指针来调用虚方法,程序将使用对象类型定义的方法,而不使用为引用或指针类型定义 ...

  4. Eclipse 反编译插件JadClipse安装

    下载jadClipse地址: 链接: http://pan.baidu.com/s/1kTN4TPd  提取码: 3fvd 将net.sf.jadclipse_3.3.0.jar拷贝到eclipse的 ...

  5. Node进阶:核心模块http简介

    本文摘录自<Nodejs学习笔记>,更多章节及更新,请访问 github主页地址.欢迎加群交流,群号 197339705. http模块概览 大多数nodejs开发者都是冲着开发web s ...

  6. Linux进程间通信之信号量

    春节过去了,真的过去一年了.在公司待了快一年了.2016希望自己变得越来越好. ps:上面那句话是年前写的,中间隔了那么久,自己也变懒了. 一.信号量 1,信号量本质是一个计数器,控制访问共享资源的最 ...

  7. SQL Server 2012新特性(1)T-SQL操作FileTable目录实例

    在SQL Server 2008提供FileStream,以借助Windows系统本身的API来强化SQL Server对于非结构化数据的支持后,SQL Server 2012更是推出了像Contai ...

  8. md5加密篇(一)

    /// <summary> /// 获取文件的md5摘要 /// </summary> /// <param name="sFile">文件流& ...

  9. 数据库系统原理——ER模型与关系模型

    原文链接: http://blog.csdn.net/haovip123/article/details/21614887 犹记得第一次看<数据库系统原理>时看天书的感觉,云里雾里:现在已 ...

  10. 为什么VC经常输出烫烫烫烫烫烫烫烫

    为什么VC经常输出烫烫烫烫烫烫烫烫 2012-05-07 11:52 by Rollen Holt, 12747 阅读, 4 评论, 收藏, 编辑 在Debug 模式下, VC 会把未初始化的栈内存全 ...