给定的shell命令有什么区别

问题描述 投票:0回答:1

我正在尝试使用shell脚本执行下面的命令但不工作:

currentdate="2018-09-21T18:00:00Z,"
ID="000db859-e1ee-40e9-8028-fa702beb643c"
echo $ID
echo $currentdate
dd="'[$currentdate "\"$ID\""]'";
echo $dd
/apollo/env/EDXClient/bin/edx parcel download --provider ucp-ipg --subject rtm-instrumentation --dataset rtm-instrumentation-dataset-hour-sliced --dataset-key $dd --destination /home/srimani/Desktop/j.txt

获得异常:“第1行偏移24遇到意外的EOF”

当我在shell下直接运行命令时它的工作:

desktop%/apollo/env/EDXClient/bin/edx parcel download --provider ucp-ipg --subject rtm-instrumentation --dataset rtm-instrumentation-dataset-hour-sliced --dataset-key '[2018-09-21T18:00:00Z,"000db859-e1ee-40e9-8028-fa702beb643c"]' --destination /home/srimani/Desktop/j.txt

谁能告诉我上面命令的区别是什么?

linux
1个回答
1
投票

shell脚本中的第一行必须是一个shebang告诉解释器用于执行脚本的程序。例如,您可以添加:#!/bin/bash

您也可以使用执行脚本手册

bash script.sh

接下来双引用dd变量,并防止全局和单词分裂。结果脚本将变为:

#!/bin/bash
currentdate="2018-09-21T18:00:00Z,"
ID="000db859-e1ee-40e9-8028-fa702beb643c"
echo $ID
echo $currentdate
dd="'[$currentdate "\"$ID\""]'"
echo "$dd"
/apollo/env/EDXClient/bin/edx parcel download --provider ucp-ipg --subject rtm-instrumentation --dataset rtm-instrumentation-dataset-hour-sliced --dataset-key "$dd" --destination /home/srimani/Desktop/j.txt

像shellcheck https://www.shellcheck.net/这样的工具可以帮助找到shell脚本中的问题。

© www.soinside.com 2019 - 2024. All rights reserved.