繁体   English   中英

这个基本的shell脚本导出东西有什么问题

[英]What's wrong with this basic shell script exporting something

$cat test
export var=value
$./test
$echo $var

我什么都没有。 我期待看到价值。

在您的情况下, test在单独的外壳(外壳的子外壳)中运行。 孩子永远不能修改父母的环境。 因此,当孩子退出时, var丢失了。

如果要在当前shell中运行脚本,请尝试:

source ./test

另外,将脚本命名为“测试”通常是一个糟糕的主意。 许多大学都有/usr/bin/test

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM