简体   繁体   中英

What's wrong with this basic shell script exporting something

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

I get nothing. I was expecting to see value.

In your case test is being run in a separate shell, a child of your shell. A child can never modify the environment of the parent. So when the child exits var is lost.

If you want to run the script in the current shell try:

source ./test

Also, it's usually a poor idea to name your scripts "test". Many unices have /usr/bin/test .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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