user3256289
user3256289

Reputation: 1

what is the difference between given shell command

I am trying execute below command using shell script but not working :

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

getting exception : "unexpected EOF encountered at line 1 offset 24"

and when I am running below command directly on shell its working:

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

can someone tell me what is the difference in above command?

Upvotes: 0

Views: 55

Answers (1)

Morten
Morten

Reputation: 11

First line in a shell script must be a shebang telling the interpreter the program to be used to execute the script. For example you could add: #!/bin/bash

You can also execute the script manual with

bash script.sh

Next double quote the dd variable when used and prevent globbing and word splitting. Resulting script would then become:

#!/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

A tool like shellcheck https://www.shellcheck.net/ can help find issues in shell scripts.

Upvotes: 1

Related Questions