簡體   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