[英]Accessing Environment Variable in Shell Script
I'm trying to create a shell script that sets an environment variable and then calls another shell script which gets that environment variable. 我正在尝试创建一个设置环境变量的Shell脚本,然后调用另一个获取该环境变量的Shell脚本。 The following code is my attempt, but it's not producing the desired result...
以下代码是我的尝试,但未产生预期的结果...
scriptOne.sh scriptOne.sh
export MYVAR=blob
bash ./scriptTwo.sh
scriptTwo.sh scriptTwo.sh
#!/bin/bash
# SIMPLE
printenv MYVAR <<END
ls || pwd && ls
ls || ls | wc || pwd && ls
END
echo
Try $MYVAR
in scriptTwo.sh you need to add a dollar to expand a shell variable. 在scriptTwo.sh中尝试
$MYVAR
,您需要添加一个美元来扩展shell变量。 I think you can call it using simply $ bash scriptTwo.sh
btw. 我认为您可以使用
$ bash scriptTwo.sh
btw简单地调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.