# /etc/profile: system-wide .profile file for the Bourne shell (sh(1)) # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). if [ "${PS1-}" ]; then if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then # The file bash.bashrc already sets the default PS1. # PS1='\h:\w\$ ' if [ -f /etc/bash.bashrc ]; then . /etc/bash.bashrc fi else if [ "`id -u`" -eq 0 ]; then PS1='# ' else PS1='$ ' fi fi fi if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r $i ]; then . $i fi done unset i fi
时间: 2024-04-13 22:25:14 浏览: 22
这是一个系统级别的配置文件,用于设置Bourne shell(sh)和兼容的shell(如bash、ksh、ash等)的环境变量和命令提示符(PS1)。在文件中,首先检查是否定义了环境变量PS1,如果定义了,则根据不同的条件设置命令提示符。如果是bash且不是以/bin/sh启动的,则使用默认的PS1值。如果是root用户,则命令提示符为"#",否则为"$"。接下来,如果存在/etc/profile.d目录,则会加载该目录下的所有以.sh结尾的文件。
这个配置文件的作用是为各种兼容的shell提供统一的系统级别配置,可以在其中设置全局的环境变量和加载其他的配置文件。
相关问题
我要一份linux中./etc.profile文件中的内容
以下是一个典型的Linux系统中/etc/profile文件的示例:
```
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH
if [ "`id -u`" -eq 0 ]; then
umask 002
else
umask 022
fi
if test -z "$MAIL" -a -f /usr/bin/biff; then
biff y
fi
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
```
这个文件主要设置了环境变量 PATH,umask,和加载了 /etc/profile.d/ 目录下的其他脚本。
#!/system/bin/sh ##!/bin/bash 什么意思
这两个开头的语句都是脚本文件的解释器说明,用于告诉操作系统使用哪种Shell解释器来执行脚本文件中的命令。具体区别如下:
- #!/system/bin/sh:是在Android系统中常用的脚本解释器说明,表示使用/system/bin目录下的sh命令来执行该脚本文件。sh是指Bourne shell,它是Unix中的一种命令行解释器,通常用于执行shell脚本。
- #!/bin/bash:是在Linux系统中常用的脚本解释器说明,表示使用/bin目录下的bash命令来执行该脚本文件。bash是Bourne-Again SHell的缩写,是Linux系统中最常用的shell解释器之一,它是sh的扩展,提供了更多的功能和特性。
需要注意的是,在脚本文件中使用不同的解释器说明可能会导致脚本在不同的操作系统中无法正常运行,因为不同的操作系统可能使用不同的Shell解释器。