| ▲ | rgrau 2 hours ago | |||||||
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.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 :) | ||||||||
| ▲ | dtj1123 an hour ago | parent [-] | |||||||
I hate weird bash tricks with a passion. The extent to which the script author gets to feel smart and efficient is exactly the extent to which the future reader of the script gets to feel like an idiot. | ||||||||
| ||||||||