0

Why does:

[ "a" != "$(printf "\na")" ] && echo true || echo false

print true while:

[ "a" != "$(printf "\n")a" ] && echo true || echo false

print false?

Vlastimil Burián
  • 27,586
  • 56
  • 179
  • 309
glarry
  • 904
  • 1
  • 7
  • 15
  • 3
    [Why does shell Command Substitution gobble up a trailing newline char?](https://unix.stackexchange.com/questions/17747/why-does-shell-command-substitution-gobble-up-a-trailing-newline-char) (and [some others](https://unix.stackexchange.com/search?q=command+substitution+newline) about the same thing) – ilkkachu Jan 27 '18 at 23:14

1 Answers1

1

I think it is because $(...). That substitution automatically remove ending newline character. That's a good default behaviour.

Bach Lien
  • 219
  • 1
  • 3