|
|
|
|
|
by keepamovin
1000 days ago
|
|
Ooh, I didn't know you could nest 'em! ChatGPT never told me that! Now we're getting somewhere! :) echo "${1:-${env_var:?I need a value for that!}}"
That is awesome! :)Like massively concise construct. I don't know what other language can compete: console.log(process.argv[2] || process.env.VAR || console.error("I need a value for that"));
I personally prefer the bash v |
|
That snippet is concise, but relies on the user supplying arguments in the order you demand. AFAICS, non-trivial scripts require you to loop over arguments, testing against long and short forms of parameters, and shifting if the parameter expects an argument.
In Powershell, you define your parameter and apply constraints. Voila:
That's it, the entire thing, done.