0

Well:

15:18 $ SECRET=Secret
15:24 $ echo -n "$SECRET" | base64
U2VjcmV0
15:24 $ base64  <<< "$SECRET"
U2VjcmV0Cg==
15:24 $ base64  <<< $SECRET
U2VjcmV0Cg==

Cg== is 0a, i.e. line feed

I find it very surprising, at least if you base your understanding on

A here string can be considered as a stripped-down form of a here document. It consists of nothing more than COMMAND <<< $WORD, where $WORD is expanded and fed to the stdin of COMMAND.

https://tldp.org/LDP/abs/html/x17837.html

PS. I guess I have to use printf '%s' then if I care about trailing newline

Jakub Bochenski
  • 3,113
  • 4
  • 33
  • 61
  • 2
    [Why does a bash here-string add a trailing newline char?](https://unix.stackexchange.com/questions/20157/why-does-a-bash-here-string-add-a-trailing-newline-char) – 0stone0 May 11 '21 at 13:35
  • OK guess my question is a cross-site duplicate, what should I do now? :o – Jakub Bochenski May 11 '21 at 13:37
  • I guess it's off-topic here on SO. So if the above linked question does not answer your question, consider asking on [unix.so](https://unix.stackexchange.com). – 0stone0 May 11 '21 at 13:38
  • 1
    Notice that it's explicit in the [manual](https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Here-Strings) ("The result is supplied as a single string, with a newline appended") – and the "why" is addressed in the U&L answer. – Benjamin W. May 11 '21 at 13:39
  • Yeah I should really be consulting the manual, too bad that tldp.org always shows up as top result in my search :P – Jakub Bochenski May 11 '21 at 13:40
  • 1
    btw @JakubBochenski: [What to do with cross-site duplicates?](https://meta.stackexchange.com/questions/4708/what-to-do-with-cross-site-duplicates). – 0stone0 May 11 '21 at 13:42

0 Answers0