News for hackers. Stuff that matters.
Re:Pure Sh Bible by ndsipa_pomu on Sunday April 30, 2023 @04:59PM (#35766573)
It's well worth learning to use printf instead of echo to avoid all the various ways that echo can break or is not well defined.

https://mywiki.wooledge.org/BashPitfalls#echo_.24foo

Re:Pure Sh Bible by koolba on Sunday April 30, 2023 @09:21PM (#35768162)
The %q format alone justifies learning about printf. Vanilla echo is for chumps.
Re:Pure Sh Bible by hddqsb on Tuesday May 02, 2023 @09:24AM (#35787061)
Note that this is supported by bash/zsh/ksh but not by POSIX sh.
Re:Pure Sh Bible by hddqsb on Tuesday May 02, 2023 @09:56AM (#35787450)
Yes. printf is not a "flex", it's the only safe way to display arbitrary strings. The link mentions one good reason to avoid echo (string might be "-n"), but another important reason is that the behaviour of echo is implementation-defined if the string contains backslashes (e.g. `echo 'foo\nbar'` displays one line in bash but two lines in dash and zsh).