bash - execute curl and export base64 file to variable -


i'm developing script downloads file, convert base64 , export code variable. @ moment can accomplish in 2 steps (which force me save file). how can directly download , export content without saving fine... i.e. in 1 line?

this i'm doing...

#!/bin/bash  -x   curl -o top10.jpg "http://www.somesite.com/top10.jpg" top10=$( base64 top10.jpg) 

thanks!

you can use process substitution:

top10=$(base64 <(curl "http://www.somesite.com/top10.jpg")) 

or, etan reisner points out in comment, pipeline work well:

top10=$(curl "http://www.somesite.com/top10.jpg" | base64) 

while process substitution results in filename getting passed base64 (either name of fifo or named file descriptor such /dev/fd/63, depending on platform), pipeline passes data base64 via stdin - net effect same here.

the advantage of using pipeline is posix-compliant, whereas process substitution bash-specific feature.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -