How to make base64 print the encoded output after a newline without newline being encoded?
I like to encode with
base64 from stdin by invoking the command pasting the input and pressing Ctrl + D twice in order to avoid a trailing newline if I don’t want one to be part of the input. It avoids
echo and leaves no data in the shell history.
However, the output is written directly after the input and it’s hard to retrieve the value:
$ base64 Input without trailing newlineSW5wdXQgd2l0aG91dCB0cmFpbGluZyBuZXdsaW5l
Is there any way I can look like
$ base64 Input without trailing newline SW5wdXQgd2l0aG91dCB0cmFpbGluZyBuZXdsaW5l
without any newlines being included in the encoded output?
I’m using Ubuntu 23.10.
Here’s a a little shell
alias that should do what you want:
alias b64='x="$(base64)"; echo; echo "$x"'
b64 and do what you suggest in the OP.