2 ms·
Well, strokes beard, funny you should ask. Have a look at https://mywiki.wooledge.org/BashPitfalls#echo_.24foo https://mywiki.wooledge.org/BashPitfalls#echo_.2
by ndsipa_pomu 2y ago
Well, strokes beard, funny you should ask.
Have a look at https://mywiki.wooledge.org/BashPitfalls#echo_.24foo https://mywiki.wooledge.org/BashPitfalls#echo_.24foo
Most of the time, "echo" works as you'd expect, but as it doesn't accept "--" to signify the end of options (which is worth using wherever you can in scripts), it'll have problems with variables that start with a dash as it'll interpret it as an option to "echo" instead.
It's a niche problem, but replacing it with "printf" is so much more flexible, useful and robust. (My favourite trick is using "printf" to also replace the "date" command).
Also, here's some more info on subtle differences between "echo" on different platforms: https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo#65819 https://unix.stackexchange.com/questions/65803/why-is-printf...
- irundebian 2y agoThank you!