Odd results on base64 operations

Compare the output of these two commands:

echo "MjAyMS0wMS0xMy56aXA="  | base64 --decode | od -c
echo "2021-01-13.zip" | od -c

You will see there is no newline character in what base64 --decode prints (because the string you start with apparently does not encode a newline character). There is a newline character in what echo prints (because this is how echo works). Now try this:

echo -n "2021-01-13.zip"  | base64

Or better:

printf '%s' "2021-01-13.zip"  | base64

Echo adds by default a trailing end of line character.

Try without adding the end of line:

> echo -n "2021-01-13.zip"  | base64
MjAyMS0wMS0xMy56aXA=

Tags:

Linux

Base64

Zsh