Comment Comment by rgrau Nice one! I love those weird bash tricks.Some of the examples here are interesting, but they show parameter substitution more than colon itself: https://tldp.org/LDP/abs/html/parameter-substitution.htmlIn small scopes, I tend to inline the `:?` validation inside the arg of the command. `echo "${1:? first param required}"`Another usecase is to use colon in the body of a while loop, while doing work in the condition of the loop. while rlwrap -o -S'>> ' tr a-z A-Z ; do :; done Gives you the "do X while it succeeds. stop when it returns non-0" semantics.I've also written about this and other bash tricks over the years in https://github.com/kidd/scripting-field-guide/blob/master/bo.... You might like them :) parent rgrau 3 months ago
Some of the examples here are interesting, but they show parameter substitution more than colon itself: https://tldp.org/LDP/abs/html/parameter-substitution.html
In small scopes, I tend to inline the `:?` validation inside the arg of the command. `echo "${1:? first param required}"`
Another usecase is to use colon in the body of a while loop, while doing work in the condition of the loop.
Gives you the "do X while it succeeds. stop when it returns non-0" semantics.I've also written about this and other bash tricks over the years in https://github.com/kidd/scripting-field-guide/blob/master/bo.... You might like them :)