Linux 如何在shell脚本中包含包含变量的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17530141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to include a file containing variables in a shell script
提问by Mercer
i have many script shell and i want to include a file containing variables in this shell
我有很多脚本外壳,我想在这个外壳中包含一个包含变量的文件
script?
脚本?
My var script:
我的 var 脚本:
###################################################################################
ORACLE_LOGIN=login
ORACLE_PWD=pwd
CHEMIN_1="/home/"
CHEMIN_2="/scripts/"
LOG_FILE="$CHEMIN_1/max.log"
export ORACLE_SID=oracle_sid
###################################################################################
My script sh:
我的脚本sh:
#!/bin/ksh
#set -x
# ============== LOAD VAR HERE ====================================
????
##################################################################
#### Begin ####
##################################################################
write "Begin . var
"
$ORACLE_HOME/bin/sqlplus -s $ORACLE_LOGIN/$ORACLE_PWD@$ORACLE_SID <<EOF >> $LOG_FILE 2>&1
@$CHEMIN_2/sp_rep_alim_dia_date_max.sql
exit
EOF
write "End."
Thx.
谢谢。
采纳答案by ams
It depends which shell, but one of these two usually works:
这取决于哪个 shell,但这两个中的一个通常有效:
source var
or
或者
. var_script
I'm not sure about ksh, but I'd imagine both would work.
我不确定 ksh,但我想两者都可以。
回答by glenn Hymanman
use the .(dot) command to source the file
使用.(点)命令来获取文件
. ./name_of_the_var_script
回答by mirabilos
That's dot + space + dot + slash + filename (because the “dot” utility needs an absolute or relative path to your var script).
那是点 + 空格 + 点 + 斜线 + 文件名(因为“点”实用程序需要 var 脚本的绝对或相对路径)。
回答by Arun Gupta
source varworked for me.
this link Pass all variables from one shellscript to another?has good explanation for this problem
source var为我工作。这个链接 将所有变量从一个 shellscript 传递到另一个?对这个问题有很好的解释
// Hope this helps..
// 希望这可以帮助..

