Reputation: 49
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.
Upvotes: 1
Views: 48
Reputation: 4622
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
Upvotes: 1