1

This is one of the weirdest things I've come across.

➜  ~ cat word.txt
mere doctrine
➜  ~ tr ' ' '\n' < ~/word.txt
mere
doctrine
➜  ~ echo $(tr ' ' '\n' < ~/word.txt)
mere doctrine

I don't understand what is the difference between executing inside $() environment and executing directly.

I am using zsh on manjaro linux.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
colin
  • 49
  • 2

1 Answers1

1

When you write, for example, echo $(ls), word splitting occurs.

The best practice is to add double quotes to prevent word splitting:

➜  ~ echo "$(tr ' ' '\n' < word.txt)"
mere
doctrine
Nick T
  • 25,754
  • 12
  • 83
  • 121
Vadik Sirekanyan
  • 3,332
  • 1
  • 22
  • 29