登录式shell的执行顺序及简单应用

来源:互联网 发布:网络跟踪 编辑:程序博客网 时间:2024/05/21 09:37

登录shell:用户登录linux主机时取得的shell。

非登录shell:用户登录linux主机后(取得了登录shell)由于需要启动执行的shell,如:用su切换用户后取得的shell;在登录shell中。

这两者在配置文件的执行顺序有着很大区别:

   1、 登录shell配置文件执行顺序
          /etc/profile-->/etc/profile.d/*.sh-->~/.bash_profile-->~/.bashrc-->/etc/.bashrc
   2、非登录shell配置文件执行顺序
        ~/.bashrc-->/etc/.bashrc-->/etc/profile.d/*.sh


再来看看简单应用:ls 和 ls -ahl是两个很常用的命令,如果你长期敲ls -ahl 会不会烦呢,可以把敲ls 变为 敲 ls -ahl 一样的效果

appledeMacBook-Pro:~ apple$ alias ls='ls -ahl'appledeMacBook-Pro:~ apple$ lstotal 148848drwxr-xr-x+  51 apple  staff   1.7K  3 30 14:56 .drwxr-xr-x    6 root   admin   204B 11 19 14:44 ..-r--------    1 apple  staff     9B 11 18 17:09 .CFUserTextEncoding-rw-r--r--@   1 apple  staff    14K  3 31 17:35 .DS_Store
写在/.bashrc上可以永久生效,

appledeMacBook-Pro:~ apple$ vim ~/.bashrcalias ls='ls -ahl'appledeMacBook-Pro:~ apple$ source ~/.bashrc  appledeMacBook-Pro:~ apple$ lstotal 148856drwxr-xr-x+  51 apple  staff   1.7K  3 31 22:12 .drwxr-xr-x    6 root   admin   204B 11 19 14:44 ..-r--------    1 apple  staff     9B 11 18 17:09 .CFUserTextEncoding-rw-r--r--@   1 apple  staff    14K  3 31 17:35 .DS_Store

其中 

source ~/.bashrc 使环境变量生效

0 0