Passing variables to this Shell Script

I'm trying to pass the variables $KMVAR_DroplrToken and $KMVAR_URL to the following shell script...

curl -XPOST -H 'Authorization: Bearer $KMVAR_DroplrToken' -H "Content-type: text/plain" -d $KMVAR_URL 'https://api.droplr.com/links'

While it seems the $KMVAR_URL variable is functioning fine within this script, it appears that the $KMVAR_DroplrToken variable is causing issues. (I know this because when I delete this variable from the script and replace it with the actual variable value, the script works as expected.)

Any insights on why this might be happening? It's odd that one variable is working in the script and not the other, but perhaps there's something I'm missing. Thanks!

Sometimes the issue is the improper use of smart quotes. But we can't see your actual code, so we can't verify that.

Sometimes the issue is the wrong type of quotes. Try replacing your single quotes with double quotes. Certain quotes prevent variable substitution, but I can't remember which ones right now, so just try double quotes.

Variables aren't expanded in single-quotes, which is why the first isn't working but the second one is.

Try either double-quotes around the auth header:

"Authorization: Bearer $KMVAR_DroplrToken"

...or ending the single-quote section immediately before the variable:

'Authorization: Bearer '$KMVAR_DroplrToken

(Note that the closing quote is after the space and immediately before the $.)

4 Likes

Thank you, @Nige_S! I tried the second of these two approaches, and it seems to work! I appreciate it.