3 ms·
My favourite shell scripting function definition technique: idempotent functions by redefining the function as a noop inside its body: foo() { foo() {
by chrismorgan 5y ago
My favourite shell scripting function definition technique: idempotent functions by redefining the function as a noop inside its body:
foo() {
foo() { true; }
echo "This bit will only be executed on the first foo call"
}
(The `true;` body is needed by some shells, e.g. bash, and not others, e.g. zsh.)
- rgrau 5y agowow, that's a great one!