微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux – 无法通过脚本文件导出变量

参见英文答案 > Global environment variables in a shell script                                    5个
我试图通过myDeploy.sh导出变量,但导出未设置.当我回应它时,它不会回响.但是,当我在命令中明确设置变量时,它正确设置并回响.Below是我的代码的片段.

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

当我回应echo $BUILD_ROOT时,它并没有回应我的路径.但是当我在命令提示符上明确地这样做时

[root@krog3-rhel5-64 GRISSOM2]# export BUILD_ROOT=/tibco/data/GRISSOM2

它设置得恰到好处并且也有回音.我错过了什么?

解决方法:

像你这样运行脚本

. ./脚本

要么

源脚本

将在当前shell上下文中执行您的脚本(不创建子shell),并且在当前shell中可以使用脚本中设置的环境变量.

从手册:

. filename [arguments]

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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐