0

I have spent an embarrassingly long time trying to solve this riddle.

I have a shell variable called API_ID which I parsed from json using jq

ludo$ echo $API_ID
> "ucjj72orp1"

Why is it that when I copy paste it like this it works fine:

aws apigateway get-resources --rest-api-id "ucjj72orp1"

and like this I get an error:

aws apigateway get-resources --rest-api-id $API_ID
An error occurred (NotFoundException) when calling the GetResources operation: Invalid REST API identifier specified 420257254224:"ucjj72orp1"
3
  • 1
    Did you use option -r in your jq command? If not, the variable $API_ID might contain double quote, that possibly makes an invalid aws id. Commented May 22, 2018 at 9:45
  • That worked! But how is it that when I input it manually with double quotes it works anyway? Commented May 22, 2018 at 9:49
  • Please see my answer Commented May 22, 2018 at 9:55

1 Answer 1

1

You need to use -r option in your jq command. This allows to get raw data without double quote.

If you set myvar=$(jq '...'), the variable will be set to a shell string including surrounding double quote.

If you copy/paste the string in an inline shell command, the shell interprets the double quote as string separator, and therefore it works.

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.