Shell脚本文件从参数文件中获取部分路径

时间:2014-11-04 12:16:51

标签: shell variables unix

我有一个参数文件(parameter.txt),其中包含如下内容:

SASH=/home/ec2-user/installers
installer=/home/hadoop/path1

我的shell脚本(temp_pull.sh)如下所示:

EPATH=`cat $1|grep 'SASH' -w| cut -d'='  -f2`
echo $EPATH
${EPATH}/data-integration/kitchen.sh   -file="$KJBPATH/hadoop/temp/maxtem/temp_pull.kjb"

当我像下面那样运行我的temp_pull.sh时:

./temp_pull.sh parameter.txt

$EPATH为我提供了正确的路径,但第3行代码只采用了部分路径。

下面粘贴了错误代码:

/home/ec2-user/installers-->out put of 2nd line  
/data-integration/kitchen.sh: No such file or directory**2-user/installer** -->out put of 3rd line

2 个答案:

答案 0 :(得分:1)

无需手动解析文件的值,因为它已经包含定义格式变量的数据:var=value

因此,如果文件足够安全,您可以source该文件,只需说出SASH就可以获得$SASH值。

然后,您可以使用以下内容:

source "$1"  # source the file given as first parameter
"$SASH"/data-integration/kitchen.sh -file="$KJBPATH/hadoop/temp/maxtem/temp_pull.kjb"

答案 1 :(得分:0)

问题是我们使用的文件是从Windows复制到UNIX.So分隔符问题是根本原因。

通过使用 dos2unix paramfile.txt ,我们可以修复isue。

命令:

dos2unix paramfile.txt

这会将所有windows的delemeter转换为unix格式。

相关问题