
profile 统一设置系统范围的环境和启动程序,用于登录设置, 是唯一的
bashrc 是专门给bash做初始化设置用的
.bash_logout 退出时的操作
.bashrc su 时操作
.bash_profile su - 才操作
- 重新登陆有效
/etc/profile
~/.bash_profile
- 开启子shell也会执行
~/.bashrc
/etc/bashrc
下面是针对profile、bashrc等配置文件的加载实验
echo -n -e "/etc/profile\t`date | cut -d' ' -f5 | cut -d: -f 2,3`\n" >> /tmp/test.txt
echo -n -e ".bashrc \t`date | cut -d' ' -f5 | cut -d: -f 2,3`\t`pwd`\n" >> /tmp/test.txt
[tom@ton ~]$pwd #当前是tom用户
/home/tom
[tom@ton ~]$cat /tmp/test.txt #首次登录均做了读写
/etc/profile 23:33
/etc/bashrc 23:33
.bashrc 23:33 /home/tom
.bash_profile 23:33 /home/tom
[tom@ton ~]$su #进入root
Password:
[root@ton ~]#pwd
/root
[root@ton ~]#cat /tmp/test.txt
...
/etc/bashrc 24:11 #此时仅对这两个文件进行了读配置
.bashrc 24:11 /home/tom
[root@ton ~]#su -
[root@ton ~]#cat /tmp/test.txt #均读了配置
...
/etc/profile 24:55
/etc/bashrc 24:56
.bashrc 24:56 /root
.bash_profile 24:56 /root
[root@ton ~]#logout #退出
[root@ton ~]#cat /tmp/test.txt
...
.bash_logout 25:25 /root #退出则访问此文件
[root@ton ~]#exit
[tom@ton ~]$cat /tmp/test.txt
/etc/profile 23:33
/etc/bashrc 23:33
.bashrc 23:33 /home/tom
.bash_profile 23:33 /home/tom
/etc/bashrc 24:11
.bashrc 24:11 /home/tom
/etc/profile 24:55
/etc/bashrc 24:56
.bashrc 24:56 /root
.bash_profile 24:56 /root
.bash_logout 25:25 /root
[tom@ton ~]$
echo `ls` 等价于 echo $(ls)
for i in "$*" $*是将所有参数作为一个整体
for i in "$@" 正确
$$ 当前进程的PID
$! 后台运行的最后一个进程的PID
变量$PS*
$PS2 一般使用于命令行里较长命令的换行提示信息
(在$PS2=" "时使用多行格式的例子,如果在一行内输入这些命令,则需要在每一个换行处加一个分号)
[root@ton profile.d]#cd /etc/profile.d/
$PS1 命令提示格式 [\u@\h \T \W]\$
PS1='[\u@\h \A \W]\$'
PS1="\[\e[1;32m\][\u@\h \W]\\$\[\e[0m\]" #$前要多加\\否则进入root不会变为(高亮显示,字体颜色为绿色)
man bash 下有
\d 星期 月 日
\h 主机名
\t HH:MM:SS
\T 12小时制
\A 24小时制 HH:MM
\u 用户名
\w 当前所在目录完事
\W 显示最后一级
\# 统计执行命令个数
\$ 提示符 区分普通和root用户
\$ 提示符 区分普通和root用户
本文详细介绍了Linux中如`.bash_profile`、`.bashrc`、`.bash_logout`和`/etc/profile`等配置文件的作用及加载顺序,强调了它们在用户登录和切换时的不同行为。同时,讨论了命令行提示符`$PS1`的定制方法及其相关符号的含义,如`d`、` `等。此外,还提及了进程ID(`$$`)和后台进程ID(`$!`)的使用。

781

被折叠的 条评论
为什么被折叠?



