How to base64 encode image in linux bash / shell

前端 未结 6 1997
说谎
说谎 2021-01-29 23:30

I\'m trying to base64 encode an image in a shell script and put it into variable:

test=\"$(printf DSC_0251.JPG | base64)\"
echo $test
RFNDXzAyNTEuSlBH

6条回答
  •  清歌不尽
    2021-01-30 00:07

    You need to use cat to get the contents of the file named 'DSC_0251.JPG', rather than the filename itself.

    test="$(cat DSC_0251.JPG | base64)"
    

    However, base64 can read from the file itself:

    test=$( base64 DSC_0251.JPG )
    

提交回复
热议问题