Why does herestring add a newline

33 views Asked by At

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

0

There are 0 answers