我有一个脚本 (A
),它以 #!/bin/sh
shebang 开头。
还有一个文件(B
)不是以#!/bin/sh
开头;它有一些我需要设置的环境变量,A
才能工作。
文件 B
运行良好,并在从 .bash_profile
执行时设置变量。例如,在我的 .bash_profile
文件中:
{. /(full_path)/(envname)/(filename).sh;}
当我在我的 A
脚本文件中写入同一行时,没有任何反应。为什么不呢?
我做了echo $env_variable_name
;这在通过 .bash_profile
执行时给了我正确的路径,但在通过我的脚本 A
时给了我空白。我试过了
-
/(full_path)/(envname)/(filename).sh
-
SCRIPT_FULL_NAME=$(readlink -f "$0") SCRIPT_PATH=$(dirname $SCRIPT_FULL_NAME) sh ${SCRIPT_PATH}/(filename).sh
我该怎么办?
最佳答案
There is another file (B) which doesn't begin with #!/bin/sh; it has some environment variables which I need to set for A to work.
在这种情况下,您应该在脚本 A 中获取您的脚本 B。要在 sh 中获取脚本,命令是:
. /path/to/B.sh
请注意,.
不是脚本 B 的相对路径的开头。
关于linux - 无法从另一个 shell 脚本执行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37540576/