ITPub博客

首页 > Linux操作系统 > Linux操作系统 > /bin/bash 和 /bin/ksh使用的用户配置文件的比较

/bin/bash 和 /bin/ksh使用的用户配置文件的比较

原创 Linux操作系统 作者:TaihangMeng 时间:2016-05-01 00:53:23 0 删除 编辑
1、/bin/bash
当用户使用/bin/bash这个shell时,用户个人配置文件的使用顺序为~/.bash_profile --> ~/.bash_login --> ~/.profile
通过下面的实践进行验证。

首先创建一个使用/bin/bash的用户: mth

  1. [root@TaylonMeng ~]# useradd -s /bin/bash mth
  2. [root@TaylonMeng ~]# su - mth
    [mth@TaylonMeng ~]$ ls -al
    total 32
    drwx------  4 mth  mth  4096 May  1 00:09 .
    drwxr-xr-x. 5 root root 4096 May  1 00:09 ..
    -rw-r--r--  1 mth  mth    18 Sep 26  2014 .bash_logout
    -rw-r--r--  1 mth  mth   176 Sep 26  2014 .bash_profile
    -rw-r--r--  1 mth  mth   124 Sep 26  2014 .bashrc
    drwxr-xr-x  2 mth  mth  4096 Jul 14  2010 .gnome2
    -rw-r--r--  1 mth  mth   171 Sep  2  2014 .kshrc
    drwxr-xr-x  4 mth  mth  4096 Mar  5 21:31 .mozilla

可以看到,默认创建的只有.bash_profile这个配置文件。我手动创建.bash_login和.profile这两个文件,并且修改三个文件的内容。

  1. [mth@TaylonMeng ~]$ ls -al
  2. total 48
  3. drwx------ 4 mth mth 4096 May 1 00:13 .
  4. drwxr-xr-x. 5 root root 4096 May 1 00:09 ..
  5. -rw------- 1 mth mth 75 May 1 00:13 .bash_history
  6. -rw-rw-r-- 1 mth mth 283 May 1 00:11 .bash_login
  7. -rw-r--r-- 1 mth mth 18 Sep 26 2014 .bash_logout
  8. -rw-r--r-- 1 mth mth 295 May 1 00:13 .bash_profile
  9. -rw-r--r-- 1 mth mth 124 Sep 26 2014 .bashrc
  10. drwxr-xr-x 2 mth mth 4096 Jul 14 2010 .gnome2
  11. -rw-r--r-- 1 mth mth 171 Sep 2 2014 .kshrc
  12. drwxr-xr-x 4 mth mth 4096 Mar 5 21:31 .mozilla
  13. -rw-rw-r-- 1 mth mth 249 May 1 00:13 .profile
  14. -rw------- 1 mth mth 1324 May 1 00:13 .viminfo

  1. [mth@TaylonMeng ~]$ more .bash_profile
  2. # .bash_profile

  3. # Get the aliases and functions
  4. if [ -f ~/.bashrc ]; then
  5.         . ~/.bashrc
  6. fi

  7. # User specific environment and startup programs

  8. PATH=$PATH:$HOME/bin

  9. export PATH

  10. echo "**************************"
  11. echo ""
  12. echo "This is '~/.bash_profile' "
  13. echo ""
  14. echo "**************************"
  15. [mth@TaylonMeng ~]$ more .bash_login
  16. # Get the aliases and functions
  17. if [ -f ~/.bashrc ]; then
  18.         . ~/.bashrc
  19. fi

  20. # User specific environment and startup programs

  21. PATH=$PATH:$HOME/bin

  22. export PATH

  23. echo "**************************"
  24. echo ""
  25. echo "This is '~/.bash_login' "
  26. echo ""
  27. echo "**************************"
  28. [mth@TaylonMeng ~]$ more .profile
  29. if [ -f ~/.bashrc ]; then
  30.         . ~/.bashrc
  31. fi

  32. # User specific environment and startup programs

  33. PATH=$PATH:$HOME/bin

  34. export PATH

  35. echo "**************************"
  36. echo ""
  37. echo "This is '~/.profile' "
  38. echo ""
  39. echo "**************************"
现在通过从root账号切换到mth账号,看显示的信息的方法,确定账号使用配置文件的顺序。

  1. [mth@TaylonMeng ~]$ exit
  2. logout
  3. [root@TaylonMeng ~]# su - mth
  4. **************************

  5. This is '~/.bash_profile'

  6. **************************
  7. [mth@TaylonMeng ~]$ mv .bash_profile .bash_profile.bk
  8. [mth@TaylonMeng ~]$ exit
  9. logout
  10. [root@TaylonMeng ~]# su - mth
  11. **************************

  12. This is '~/.bash_login'

  13. **************************
  14. [mth@TaylonMeng ~]$ mv .bash_login .bash_login.bk
  15. [mth@TaylonMeng ~]$ exit
  16. logout
  17. [root@TaylonMeng ~]# su - mth
  18. **************************

  19. This is '~/.profile'

  20. **************************
通过上面的显示信息,验证了上面所写的读取顺序。

2、/bin/ksh

首先创建一个使用/bin/ksh的用户: zyx

  1. [root@TaylonMeng ~]# useradd -s /bin/ksh zyx
  2. [root@TaylonMeng ~]# su - zyx
    $ ls -al
    total 36
    drwx------  4 zyx  zyx  4096 May  1 00:31 .
    drwxr-xr-x. 6 root root 4096 May  1 00:31 ..
    -rw-r--r--  1 zyx  zyx    18 Sep 26  2014 .bash_logout
    -rw-r--r--  1 zyx  zyx   176 Sep 26  2014 .bash_profile
    -rw-r--r--  1 zyx  zyx   124 Sep 26  2014 .bashrc
    drwxr-xr-x  2 zyx  zyx  4096 Jul 14  2010 .gnome2
    -rw-r--r--  1 zyx  zyx   171 Sep  2  2014 .kshrc
    drwxr-xr-x  4 zyx  zyx  4096 Mar  5 21:31 .mozilla
    -rw-------  1 zyx  zyx    16 May  1 00:33 .sh_history
可以看到默认创建的也是.bash_profile这个配置文件,下面我先修改.bash_profile文件的内容。同样也是加上上面用过的显示信息。

  1. $ vi .bash_profile
  2. # .bash_profile

  3. # Get the aliases and functions
  4. if [ -f ~/.bashrc ]; then
  5.         . ~/.bashrc
  6. fi

  7. # User specific environment and startup programs

  8. PATH=$PATH:$HOME/bin

  9. export PATH

  10. echo "**************************"
  11. echo ""
  12. echo "This is '~/.bash_profile' "
  13. echo ""
  14. echo "**************************"
  15. $ exit
    [root@TaylonMeng ~]# su - zyx
    $
可以看到,没有任何显示信息。所以可以判断,/bin/ksh并不使用 ~/.bash_profile作为账号的个人配置文件。

下面验证~/.bash_login文件。

  1. $ vi .bash_login
  2. # Get the aliases and functions
  3. if [ -f ~/.bashrc ]; then
  4.         . ~/.bashrc
  5. fi

  6. # User specific environment and startup programs

  7. PATH=$PATH:$HOME/bin

  8. export PATH

  9. echo "**************************"
  10. echo ""
  11. echo "This is '~/.bash_login' "
  12. echo ""
  13. echo "**************************"
  14. $ exit
    [root@TaylonMeng ~]# su - zyx
    $
同样没有任何显示信息,所以判断,/bin/ksh也不使用 ~/.bash_login作为账号的个人配置文件。

最后验证~/.profile文件。

  1. $ vi .profile
  2. # User specific environment and startup programs

  3. PATH=$PATH:$HOME/bin

  4. export PATH

  5. echo "**************************"
  6. echo ""
  7. echo "This is '~/.profile' "
  8. echo ""
  9. echo "**************************"
  10. $ exit
    [root@TaylonMeng ~]# su - zyx
    **************************


    This is '~/.profile'


    **************************
    $
根据显示信息,我推断,/bin/ksh只使用 ~/.profile作为账号的个人配置文件。

总结如下:
  • 当用户使用/bin/bash这个shell时,用户个人配置文件的使用顺序为~/.bash_profile --> ~/.bash_login --> ~/.profile;
  • 当用户使用/bin/ksh这个shell时,只会使用~/.profile作为用户个人配置文件。






来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30776559/viewspace-2091391/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2016-01-07

  • 博文量
    101
  • 访问量
    147092