1

I want to replace KEY in curl command with variable value in shell script.

KEY=KEY_VALUE

My curl command is as follow.

curl -s "https://api.kite.trade/quote?i=NSE:NIFTY+50&i=NSE:INF" -H "X-Kite-Version: 3" -H "Authorization: token XYZ:KEY"

Thanks in advance

1
  • 2
    Does anything speak against turning the string KEY into a parameter expansion $KEY and setting the variable KEY to whatever you want? Commented Jul 21, 2021 at 9:41

1 Answer 1

1

Fix your quotes and use the variable:

key=key_value
curl -s 'https://api.kite.trade/quote?i=NSE:NIFTY+50&i=NSE:INF' \
    -H 'X-Kite-Version: 3' -H "Authorization: token XYZ:${key}"

Use single quotes for strings that aren't interpolated (this allows you to not need to worry about whether or not there are any characters in the string that may be modified by interpolation, eg backslashes or dollar signs), and don't use variables with all cap names.

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.