首页 > 解决方案 > 如何在 UNIX shell 脚本中传递最终文件名

问题描述

inputLandingFullPath="$1"
inputDataFileName="$2"
inputLogFullPath="$3"
inputLoadingPath="$4"
Datalake_Key="$5"
Datalake_Id="$6"
InputScheme=${inputDataFileName:19:2}
echo "$InputScheme"
touch ${inputLoadingPath}\tmp-${InputScheme}.json
cp ${inputLoadingPath}\tmp-${InputScheme}.json ${inputLoadingPath}\${InputScheme}.json

当我用它指定一个字符串时,连接工作正常,但当我没有它指定时就不行。

这工作正常,产生文件 tmp-YS-json:

touch ${inputLoadingPath}\tmp-${InputScheme}.json

这不起作用:

cp ${inputLoadingPath}\tmp-${InputScheme}.json ${inputLoadingPath}\${InputScheme}.json

输出是:

YS

tmp-YS.json.part5

${InputScheme}.json

所需的输出是:

YS.json

论据:

sh /Hadoop_SAN/TU_Prod/TMP/BB_Parse_JSON.sh '/Hadoop_SAN/TU_Prod/TMP/' 'tesco_qhv5_extract-YS-2018.08.15.json' '/Hadoop_SAN/TU_Prod/TMP/' '/Hadoop_SAN/TU_Prod/TMP/' 0 0 

标签: shellunixargumentsfilenames

解决方案


而不是使用反斜杠使用正斜杠指定 / 而不是 \

${inputLoadingPath}/${InputScheme}.json


推荐阅读