你好,游客 登录 注册 搜索
背景:
阅读新闻

AIX环境变量简介及使用

[日期:2012-12-24] 来源:Linux社区  作者:bobo12082119 [字体:大 中 小]

6.set命令
在$HOME.profile文件中,设置环境变量时,除了export可以导出之外,还有set -a命令,
可以指明所有变量直接被导出;不过别在/etc/profile中设置,在自己的$HOME.profile中设置。

下面是一个shell脚本的实例
在father.sh脚本中,调用child.sh脚本,并修改father.sh中的变量值,如下:
pg father.sh
# father script
echo "This is the father"
SMART_PHONE="iPhone 5"
echo "I have the phone:$SMART_PHONE"
# call the child script
sh child.sh
echo "The phone father owned is:$SMART_PHONE"

pg child.sh
# child
echo "called from father..i am the child"
echo "phone is:${SMART_PHONE:-unknow}"
SMART_PHONE="Meizu MX2"
echo "changing SMART_PHONE to:$SMART_PHONE"
执行脚本:
sh father.sh
This is the father
I have the phone:iPhone 5
called from father..i am the child
phone is:unknow ->①不认识父进程中的变量
changing SMART_PHONE to:Meizu MX2
The phone father owned is:iPhone 5
可以看到,在子进程中并不认识父进程中的变量,这是因为我们没在父进程中导出变量值。
修改father.sh脚本:
pg father.sh
# father script
echo "This is the father"
SMART_PHONE="iPhone 5"
echo "I have the phone:$SMART_PHONE"
# call the child script
export SMART_PHONE ->②
sh child.sh
echo "The phone father owned is:$SMART_PHONE"
现在执行修改后的脚本,子进程认识父进程传递过来的变量了:
sh father.sh
This is the father
I have the phone:iPhone 5
called from father..i am the child
phone is:iPhone 5 ->①导出之后,认识了
changing SMART_PHONE to:Meizu MX2
The phone father owned is:iPhone 5

linux
相关资讯       AIX  AIX环境变量 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款