shell - 如何在 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
解决方案
而不是使用反斜杠使用正斜杠指定 / 而不是 \
${inputLoadingPath}/${InputScheme}.json
推荐阅读
- javascript - 使用条件过滤项目(vue.js)
- javascript - 云功能触发时子集合 Firestore 获取文档 ID
- reporting-services - SSRS 将分钟更改为日、小时和分钟
- c++ - 尝试使用 switch 和 if 语句创建日历来检查用户输入,然后输出日期
- java - Gradle 在编译任务中使用 jar-with-dependencies
- clojure - 如何在 clojure 中记住 api 响应?
- pentaho - Pentaho 数据集成为列中每个分隔值的新行
- function - 为什么 ocaml 忽略一个功能而其余的都做?
- sql - 有没有办法在sql中将varchar转换为int值?
- c - 如何在C中复制空字符串中的字符?