shell如何传递变量到另一个脚本文件中
一,有如下的shell脚本。
father.sh
echo "this is the father"
FILM="A Few Good Men"
echo "I like the film : $FILM"
#call the child script
#export FILM
./child.sh
echo "back to father"
echo "and the film is : $FILM"
exit
二,子shell脚本代码:child.sh
echo "called from father...i am the child"
echo "filem name is : $FILM"
FILM="Die Hard"
echo "changing film to :$FILM"
exit
结果如下:
解析:这是因为 father 中并没有导出变量 FILM 给 child。
当 father 把 变量 FILM 导出给 child,child脚本就知道了 FILM变量的值了,结果如下:
因为 father 把变量 FILM用 export命令导出了,所以任意的脚本都可以使用 变量 FILM 了,它们将继承的 FILM的所有权。
注意:不可以将子进程的变量导出到父进程;要实现这一点,可以通过重定向。
您可能感兴趣的文章:
shell如何传递变量到另一个脚本文件中
Shell脚本参数传递方法
深入解析tcsh的初始化配置文件
awk基础知识(3)-调用外部脚本
shell变量$#,$@,$0,$1,$2详解
Linux Source命令解析
shell特殊变量的含义
inux shell初级入门教程
shell编程中的几个小技巧
如何在shell脚本里传递一个变量给awk