BASH:在我的脚本中设置环境变量并没有在其他任何地方设置它 - 我如何全局导出?简单的例子

时间:2013-08-28 01:42:30

标签: bash unix environment-variables

PROMPT> pwd
/Users/jon/dev/test

PROMPT> ls -al
total 8
drwxr-xr-x   3 jon   102B Aug 27 21:34 ./
drwxr-xr-x  14 jon   476B Aug 27 21:33 ../
-rwxr-xr-x   1 jon   147B Aug 27 21:34 init*

PROMPT> cat init
#!/bin/sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export SCRIPT_HOME=${DIR%/bin}
echo "SCRIPT_HOME has been set to: $SCRIPT_HOME"

PROMPT> ./init
SCRIPT_HOME has been set to: /Users/jon/dev/test

PROMPT> echo $SCRIPT_HOME

PROMPT> why did that command not work?
-bash: why: command not found

PROMPT> 

1 个答案:

答案 0 :(得分:1)

相反,您应该尝试以下方法:

PROMPT>. ./init

注意额外的点../init之间的空格。这很重要。它类似于source init