4 ms·
why is printf preferable to echo here other than formatting?
by cat199 6y ago
why is printf preferable to echo here other than formatting?
- deleted 6y ago[deleted]
- stonewareslord 6y agoEcho is defined differently in different shells ("not portable"). Also it can have arguments which breaks things sometimes: echo Option -n invalid # OK echo -n is not valid # Uh oh printf '%s ' -n is not valid # Always okay Generally you should use printf because of its consistency. For a simpler example of OP's: panic() { printf '%s\n' "${0}: ${*}"; exit 1; } Is fine. I don't see the need to pass a format string to your function. Just call: panic "${download_url}: unable to download"