无法变量通过脚本文件导出 [英] Unable to export the variable through script file
问题描述
我想通过myDeploy.sh导出一个变量,但出口是没有得到设置。当我附和它不呼应。然而,当我在命令明确设置变量它设置正确,又呼应too.Below是我的code的片段。
I am trying to export a variables through myDeploy.sh but the export is not getting set. When i am echoing it is not echoing. However, when i set the variable explicitly on command it sets properly and echoes too.Below is the snippet of my code.
myDeploy.sh
myDeploy.sh
#!/bin/bash
# export the build root
export BUILD_ROOT=/tibco/data/GRISSOM2
export CUSTOM1=/tibco/data/GRISSOM2/DEPLOYMENT_ARTIFACTS/common/MDR_ITEM_E1/rulebase
export CLEANUP=$BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common
cd $BUILD_ROOT/DEPLOYMENT_ARTIFACTS/common
当我回声回声$ BUILD_ROOT
它不是呼应了我的道路。但是,当我做明确的命令提示符像
When I echoes echo $BUILD_ROOT
it is not echoing the path for me. But when I do it explicitly on command prompt like
[root@krog3-rhel5-64 GRISSOM2]# export BUILD_ROOT=/tibco/data/GRISSOM2
它正确地设置并回了。我缺少什么?
It sets properly and echoes too. What am I missing?
推荐答案
运行脚本像
。 ./script
或
源脚本
将在当前shell环境中执行脚本(不创建一个子shell),并在脚本中设置环境变量将可你的电流的外壳。
would execute your script in the current shell context (without creating a subshell) and the environment variables set within the script would be available in your current shell.
这本手册:
。的文件名的[参数的]
阅读,并在电流从的文件名的执行命令的参数
外壳上下文。如果的文件名的不包含斜杠,在 PATH
变量
用于查找文件名。当bash是不是在 POSIX
模式下,电流
如果文件名没有在 $ PATH
发现目录中搜索。如果有任何
提供参数,成为他们的位置参数时,
的文件名的执行。否则,位置参数
不变。返回状态是最后一个命令的退出状态
执行,或者零,如果没有执行命令。如果的文件名的不
找到,或者不能被读取,返回状态是非零。此内置
相当于源
。
Read and execute commands from the filename argument in the current
shell context. If filename does not contain a slash, the PATH
variable
is used to find filename. When Bash is not in POSIX
mode, the current
directory is searched if filename is not found in $PATH
. If any
arguments are supplied, they become the positional parameters when
filename is executed. Otherwise the positional parameters are
unchanged. The return status is the exit status of the last command
executed, or zero if no commands are executed. If filename is not
found, or cannot be read, the return status is non-zero. This builtin
is equivalent to source
.
这篇关于无法变量通过脚本文件导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!