您的位置:首页 > 运维架构 > Shell

Linux学习---shell编程(04-环境变量配置文件)

2016-09-06 13:23 726 查看
1.source命令

source 配置文件 或者 . 配置文件
# 让配置文件立即生效。

 

2. 环境变量配置文件作用

环境变量配置文件中主要定义对系统的操作环境生效的默认环境变量,比如PATH, PS1, HOSTNAME等。

PATH = “$PATH”:/Users/yesiming#临时生效

3.环境变量的位置

/etc/profile

/etc/profile.d/*.sh

~/.bash_profile

~/.bashrc

/etc/bashrc

 

执行顺序

/etc/profile à/etc/profile.d/*.sh(lang.sh)

à~/.bash_profileà~/.bashrc à/etc/bashrc(这里有了不登录设置环境变量)

 

/etc/profile的作用

pathmunge () { #设置path
    case":${PATH}:"in
        *:"$1":*)
            ;;
        *)
            if ["$2"="after"]
; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}
 
 
if [-x /usr/bin/id
]; then
#记录当前登录用户的id
    if [-z"$EUID"];
then
        # ksh workaround
        EUID=`id -u`
        UID=`id -ru`
    fi
    USER="`id -un`"
#记录登录用户名称
    LOGNAME=$USER
#设置登录用户名称
    MAIL="/var/spool/mail/$USER"
#设置用户邮箱地址
fi
 
# Path manipulation
if ["$EUID"="0"];
then #超级用户环境变量
    pathmunge /sbin
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
#普通用户环境变量
    pathmunge /usr/sbin after
    pathmunge /sbin after
fi
 
HOSTNAME=`/bin/hostname
2>/dev/null`
#定义主机名
HISTSIZE=1000                             #定义历史命令条数
if ["$HISTCONTROL"="ignorespace"]
; then
    export HISTCONTROL=ignoreboth
else
    export HISTCONTROL=ignoredups
fi
 
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
 
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [$UID-gt199] &&
["`id -gn`"="`id -un`"];
then #设置umask
    umask002
else
    umask022
fi
 
for i
in /etc/profile.d/*.sh ;
do #调用profile.d/下的所有shell
    if [-r"$i"];
then
        if ["${-#*i}"!="$-"];
then
            . "$i"
        else                                                                                                                                                                                                              
                                 
            . "$i">/dev/null
2>&1                                                                                                                                                                                                                         

        fi                                                                                                                                                                                                                                                  
    fi                                                                                                                                                                                                                                                      
done                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                            
unset i                                                                                                                                                                                                                                                     
unset-f pathmunge

 

Shell登录信息

本地终端欢迎信息:/etc/issue

\d

显示当前系统时间

\s

显示操作系统名称

\l

显示登录的终端号,

\m

显示硬件体系结构,比如i386, i686

\n

显示主机名

\o

显示域名

\r

显示内核版本

\t

显示当前系统时间

\u

显示当前登录用户序列号

 

远程终端欢迎信息:/etc/issus.net

a.     转译符不再生效

b.     是否显示欢迎信息,由ssh的配置文件/etc/ssh/sshd_config决定,加入”Banner/etc/issue.net”行才能显示(要重启ssh服务)

 

登录后的欢迎信息:/etc/motd

不管是本地登录,还是远程登录,都可以显示该欢迎信息
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: