shell脚本从shell脚本中读取变量

时间:2013-06-24 06:54:16

标签: shell

如何采用这样的变量?

a.sh

#!/bin/sh
./b.sh
echo "The message is: $MESSAGE"

b.sh

#!/bin/sh
MESSAGE="hello"

然后运行:

$ ./a.sh
The message is:

我想在a.sh

中获取变量MESSAGE的值

我该怎么办?

1 个答案:

答案 0 :(得分:1)

如果你. ./b.sh(或source b.sh取决于你的shell风味),它将在同一个shell中运行b,而不是启动另一个进程。