3 ms·
It's one of those things where the exact rules are complex and easy to misremember. Ironically, your two scripts demonstrate one way in which the problem arise
by JdeBP 6y ago
It's one of those things where the exact rules are complex and easy to misremember. Ironically, your two scripts demonstrate one way in which the problem arises. The rules are different for each script, because the command expansions are in different contexts. And when someone in the future decides to make your code into a shell function with local variables, suddenly the rules change again.
For maintainability, for safety, for the people who come after one, and for one's own sanity, the general advice is to always quote.
* https://mywiki.wooledge.org/Quotes https://mywiki.wooledge.org/Quotes
* https://unix.stackexchange.com/q/97560/5132 https://unix.stackexchange.com/q/97560/5132
* https://unix.stackexchange.com/q/68694/5132 https://unix.stackexchange.com/q/68694/5132
* https://unix.stackexchange.com/q/131766/5132 https://unix.stackexchange.com/q/131766/5132