0

I'm trying to get files from specific folder, load them with curl and get result to variable:

#!/bin/bash
shopt -s nullglob
FILES=*
for f in $FILES
do
  core=$f
  #echo "curl -H \"Content-Type: application/json\" --data-binary @$f http://v-cdh-master:8983/solr/$core/update/json?commit=true"
  result=$(curl -H "Content-Type: application/json" -s --data-binary @$f http://v-cdh-master:8983/solr/$core/update/json?commit=true)
done

The result of running this script is

curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information

If I remove comment from echo string I could see the valid url like this

curl -H "Content-Type: application/json" --data-binary @affiliates_multival http://v-cdh-master:8983/solr/affiliates_multival/update/json?commit=true

Which works perfect when I copy/paste it to terminal.

Where is my mistake?

1 Answer 1

2

The ? in the URL causes the entire argument to be treated as a glob, which is not matching a file. Since you have the nullglob option enabled, the word is removed from the call to curl. Quoting the argument, as you do with the echo command, will resolved the problem by preventing pathname generation.

result=$(curl -H "Content-Type: application/json" -s --data-binary @"$f" "http://v-cdh-master:8983/solr/$core/update/json?commit=true")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.