I'd like to POST the Base64 encoding of a file to a server, combining curl and base64 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 executing base64 hello.txt. So how do I do it properly?
Combine curl and base64 into one command?
shell;quoting;command substitution
When you use simple quotes, nothing is interpreted:~$ echo 'foo:$var bar:$(base64 foo) something'foo:$var bar:$(base64 foo) somethingYou have to unquote if you want the interpretation:~$ echo 'foo:'$var' bar:'$(base64 foo)' something'foo:foo bar:Zm9vCg== somethingAnd 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