1

I've got the following call in a bash script I'm creating

response= curl -X POST $URL -u "$USER:$PASSWORD" --data-urlencode "key=$key" --data "label=pub_key" -o /dev/null --silent --write-out "%{http_code}"

I can see 200 being written to the console however $response always ends up null.

I've also tried the following but it was not better.

response= $(curl -X POST $URL -u "$USER:$PASSWORD" --data-urlencode "key=$key" --data "label=pub_key" -o /dev/null --silent --write-out "%{http_code}")

Any help for a bash noob would be appreciated.

1 Answer 1

4

Space -- the final frontier:

response=$(curl -X ...)

Note: no spaces around the =. The shell is white-space sensitive in a few places and variable assignments are one of them.

With the space, as in var= command args, you set var as empty in a one-shot assignment and then run command.

Sign up to request clarification or add additional context in comments.

2 Comments

Spot on! It seems I have some reading to do on variable assignment syntax. Thanks :)
It's more accurate to say the shell is extremely whitespace sensitive. It's not that response= foo is some sort of syntax error compared to response=foo; each is a completely valid syntax for two completely different operations. (The first calls the command foo with the variable response set to an empty string in its environment; the second is a variable assignment.)

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.