0

I have failed to understand the following behaviour. First encoding that seems ok to me:

$ echo -n "Cg==" | base64 -d | xxd
00000000: 0a
$ echo -n "Cgo=" | base64 -d | xxd
00000000: 0a0a

When I assign the decoding to a variable I lose LF in the process.

$ VAR=$(echo -n "Cg==" | base64 -d)
$ echo -n $VAR | xxd
$ VAR=$(echo -n "Cgo=" | base64 -d)
$ echo -n $VAR | xxd
$

That is I do not get anything back other then null ("") instead of 0a and 0a0a respectively. What am I missing? Mistake in the example? Is this expected behaviour?

Olof
  • 1
  • 2
  • You always loose LF with this syntax, take a look at [this](https://stackoverflow.com/questions/3005963/how-can-i-have-a-newline-in-a-string-in-sh). – rugolinifr Jul 28 '20 at 22:11
  • Thanks, read the post and one of the answers seems to fit the above: @ismael No, $() is specified by POSIX as removing sequences of one or more characters at the end of the substitution. – Jens Jun 3 '14 at 8:21 – Olof Jul 28 '20 at 22:44
  • I have to rethink my demo code and possibly code it directly in a suitable non-shell language. – Olof Jul 28 '20 at 22:52

0 Answers0