Combine curl and base64 into one command?
13,121
When you use simple quotes, nothing is interpreted:
~$ echo 'foo:$var bar:$(base64 foo) something'
foo:$var bar:$(base64 foo) something
You have to unquote if you want the interpretation:
~$ echo 'foo:'$var' bar:'$(base64 foo)' something'
foo:foo bar:Zm9vCg== something
And since you don't know what it can contain, it's better to double quote:
~$ echo 'foo:'"$var"' bar:'"$(base64 foo)"' something'
foo:foo bar:Zm9vCg== something
Related videos on Youtube
Author by
XåpplI'-I0llwlg'I -
Updated on September 18, 2022Comments
-
XåpplI'-I0llwlg'I - almost 2 years
I'd like to POST the Base64 encoding of a file to a server, combining
curl
andbase64
into one command that I can execute. I've tried the following:curl 'http://localhost:5000/files' -X POST -H 'Content-Type: application/json' -d '{"file": "$(base64 hello.txt)"}'
But it just POSTs the string literal
"$(base64 hello.txt)"
, instead of substituting the result of executingbase64 hello.txt
. So how do I do it properly?-
fredtantini about 9 yearsIf you try
curl 'http://localhost:5000/files' -X POST -H 'Content-Type: application/json' -d '{"file": "'"$(base64 hello.txt)"'"}'
? (that is, "unquote" the bash command$(...)
but protected by surrounding by double quotes
-