[英]Unable to execute a script from another shell script
I have a script ( A
) which begins with a #!/bin/sh
shebang. 我有一个以
#!/bin/sh
shebang开头的脚本( A
)。
There is another file ( B
) which doesn't begin with #!/bin/sh
; 还有另一个文件(
B
),它不是以#!/bin/sh
开头的; it has some environment variables which I need to set for A
to work. 它具有一些环境变量,我需要为
A
设置这些变量。
The file B
runs fine, and sets the variables when executed from .bash_profile
. 文件
B
运行良好,并从.bash_profile
执行时设置了变量。 For example, in my .bash_profile
file: 例如,在我的
.bash_profile
文件中:
{. /(full_path)/(envname)/(filename).sh;}
When I write same line in my A
script file, nothing happens. 当我在
A
脚本文件中写同一行时,什么也没发生。 Why not? 为什么不?
I did echo $env_variable_name
; 我确实
echo $env_variable_name
; this gives me the correct path when executed via .bash_profile
but gives me blank when via my script A
. 当通过
.bash_profile
执行时,这给了我正确的路径,但是当通过脚本A
执行时,给了我空白。 I tried 我试过了
/(full_path)/(envname)/(filename).sh
SCRIPT_FULL_NAME=$(readlink -f "$0") SCRIPT_PATH=$(dirname $SCRIPT_FULL_NAME) sh ${SCRIPT_PATH}/(filename).sh
What should I do? 我该怎么办?
There is another file (B) which doesn't begin with #!/bin/sh;
还有另一个文件(B),它不以#!/ bin / sh开头; it has some environment variables which I need to set for A to work.
它具有一些环境变量,我需要为A设置这些变量。
In this case you should source you script B in script A. To source a script in sh, the command is: 在这种情况下,你应该源时,脚本B在脚本A.为源SH脚本的命令是:
. /path/to/B.sh
Note that the .
请注意
.
is not the beginning of a relative path to script B. 不是脚本B相对路径的开头。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.