3

I am trying to upload a JSON file into my noSQL database using a bash script, but it doesn't work and I don't understand why.

This is the script :

test='{"evaluation": "none"}'
test="'$test'"
command="curl -XPUT localhost:9200/test/evaluation/$i -d $test"
echo "$command"
$command 

This is the error :

curl -XPUT localhost:9200/test/evaluation/0 -d '{"evaluation": "none"}'
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}curl: (3) [globbing] unmatched close brace/bracket in column 7

When I do the command given in my command line it works fine though.

What is the error here ? Thank you

1
  • 2
    See Bash FAQ 50 Commented May 11, 2017 at 15:42

1 Answer 1

2

Don't store a command in a variable; if you absolutely must have something usable with logging, put the arguments in an array.

test='{"evaluation": "none"}'
args=( -XPUT localhost9200/test/evaluation/"$i" -d "$test" )
echo "curl ${args[*]}"
curl "${args[@]}"
Sign up to request clarification or add additional context in comments.

1 Comment

thank you ! I've been wondering on the problem for a while and this solution works perfectly

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.