Shell脚本文件采用参数文件的部分路径

Shell脚本文件采用参数文件的部分路径,shell,variables,unix,Shell,Variables,Unix,我有一个参数文件(parameter.txt),其中包含如下内容: SASH=/home/ec2-user/installers installer=/home/hadoop/path1 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_

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

SASH=/home/ec2-user/installers
installer=/home/hadoop/path1
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 parameter.txt
我的shell脚本(temp_pull.sh)如下所示:

SASH=/home/ec2-user/installers
installer=/home/hadoop/path1
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 parameter.txt
当我运行temp_pull.sh时,如下所示:

SASH=/home/ec2-user/installers
installer=/home/hadoop/path1
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 parameter.txt
$EPATH
为我提供了正确的路径,但第三行代码只使用部分路径

错误代码粘贴在下面:

/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

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

因此,如果该文件足够安全,则只需说出
$SASH
,即可访问该文件,从而使
SASH
值可用

然后,您可以使用以下选项:

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

问题是我们使用的文件是从windows复制到UNIX的。所以分隔符问题是根本原因

通过使用dos2unix paramfile.txt我们能够修复isue

命令:

dos2unix paramfile.txt

这将把windows的所有数据表转换为unix格式。

您可以通过将另一个文件中的值来源为:
source“$1”来更优雅地使用它
然后你就可以直接使用
$SASH
了。谢谢fedorqui..你能详细说明你的答案吗..我不太精通shellscripting..如果我的文件中有多个参数,该如何处理。我已经编辑了这个问题。然后你还可以使用
$installer
!嘿..我试过了..我得到了同样的准确错误..它获取了部分数据。你应该确保文件
/home/ec2 user/installers/data integration/kitchen.sh
存在。我理解你的观点..但是脚本中的SASH值无法替换。它正在获取部分字段。就像这个2用户/安装程序。这不是完整的路径。这就是它给出错误的原因。