I am updating an old script and came across a pattern I am unfamiliar with:
# NOTE The | : always returns true so the <cmd> doesn't fail
<cmd> | :
I've only ever seen this pattern used in a fork bomb example. If someone were to ask me how to accomplish what is stated in the comment, I would have suggested:
<cmd> ||:
Before I chalk this up to a typo, has anyone seen this pattern and able to explain its use-case?
| :
will cause failure when the program on the left-hand side tries to write to its stdout after the copy of:
/true
has already exited, whereas> /dev/null
will work for any arbitrary amount of content. – Sporulate