Re:A shell colon does nothing. Use it anyway.
by normie3000 on Sunday July 26, 2026 @01:55AM
(#49055154)
Prefer
over
Really? Colon is the appendix of the shell.
[ Parent
| on HN ]
Re:A shell colon does nothing. Use it anyway.
by yjftsjthsd-h on Sunday July 26, 2026 @02:36AM
(#49055387)
Aside: hacker news doesn't do markdown code blocks, but instead uses 2 spaces before text;
if x then :; else something; fi
Re:A shell colon does nothing. Use it anyway.
by normie3000 on Sunday July 26, 2026 @02:59AM
(#49055479)
Thanks, fixed
First of all, I must salute you on the joke; well put haha!
---
It is a (contrived) example of usage where a command is required and `:` can fill in the blanks. There are certainly scenarios where negating an expression becomes harder than doing the "dumb" way, and I for one has written code where `:` can be used as a placeholder meaning "fill this in later" or equivalent.
With that said, 100% agree with you that in actual "production" code - there is always a cleaner way.
Re:A shell colon does nothing. Use it anyway.
by bodyfour on Sunday July 26, 2026 @04:21AM
(#49055889)
The "if !" syntax isn't available on old enough shells.
Probably not an issue for most people in 2026 -- you have to back pretty far for it to be missing. Technically, though, "if x; then :; else" is more portable.