shell的环境变量
2011-05-14 09:57
106 查看
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
用户登录时,自动读取/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
相关文章推荐
- linux之基础shell脚本编程4 字符串操作,变量赋值,配置用户环境
- 【Bash百宝箱】shell环境变量有哪些
- shell脚本中的SQL*Plus的环境变量
- linux命令行与shell脚本大全_第五章_使用环境变量
- appium在dmg安装后 MAC的环境变量设置(配置后可以shell启动)
- shell 脚本实战笔记(2)--环境变量PATH的恩怨情仇
- shell脚本中使用自定义命令之一---使用环境变量的方式
- 管道符和作业控制,shell变量和环境变量配置文件
- 第1章 BashShell命令------------(默认的shell环境变量与path变量的设置)
- 8.6 管道符和作业控制 8.7/8.8 shell变量 8.9 环境变量配置文件
- Shell基础-环境变量配置文件-其他配置文件和登录信息
- crontab启动shell脚本的环境变量问题
- 总结linux环境几个特殊的shell变量
- LINUX系统学习笔记管道符和作业控制 ,shell变量 , 环境变量配置文件
- shell 环境变量
- awk中使用shell的环境变量方法
- Linux命令行与shell脚本(3)--环境变量
- 全新 Mac 安装指南(编程篇)(环境变量、Shell 终端、SSH 远程连接)
- Mac 设置环境变量,并根据shell修改而修改变量的位置
- ubuntu配置全局环境变量后开新shell变量无效的解决方法