shell的环境变量

1./etc/profile 

用户登录时,自动读取/ect目录下profile文件,此文件包括

  • 全局或局部环境变量
  • PATH信息
  • 终端设置
  • 安全命令
  • 日期信息或放弃操作信息

2.stty用法

stty用于设置终端特性。要查询现在的stty选项,使用stty -a

$stty -a

stty的一个选项为-g,此选项允许以只读格式保存stty现有设置,便于以后重置回stty.

3.显示变量

使用echo命令可以显示单个变量,并在变量名前加$,例如:

$ DOLLAR=99

$ echo ${DOLLAR}

99

$ LAST_FILE=s2

$ echo ${LAST_FILE}

s2

$ ERROR="This is user: $LOGNAME"

$ echo ${ERROR}
This is user: dongjichao

4.清除变量

使用unset命令清除变量

$ PC=enterprise

$ echo ${PC}

enterprise

$ unset PC

$ echo ${PC}

$

5.显示所有本地shell变量

$ set | more

6.测试变量是否已经设置

$ echo "The file is ${FILES:?}"

FILES: parameter null or not set

7.显示环境变量

$ CONSOLE=tty1;  export CONSOLE

$ echo $CONSOLE

tty1

使用env命令可以查看所有的环境变量

$ env

8.使用export导出变量

有一父进程

$ cat father.sh
#!/bin/sh
echo "this is the father"
FILM="A Few Good Men"
echo "I like the file :$FILM"
#call the child script
export FILM    #去掉此句,在child.sh中变量$FILM则为空
child.sh
echo "back to father"
echo "and the file is :$FILM"

子进程为
$ cat child.sh
#!/bin/sh
echo "called from father.. i am the child"
echo "film name is :$FILM"
FILM="Die Hard"
echo "changing file to :$FILM"

运行father输出:

$ father.sh
this is the father
I like the file :A Few Good Men
called from father.. i am the child
film name is :A Few Good Men
changing file to :Die Hard
back to father
and the file is :A Few Good Men

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值