You can also nest those, so this way you can get a value from an argument, or an env var, and if none is set, error.
echo "${1:-${env_var:?I need a value for that!}}" echo "${1:-${env_var:?I need a value for that!}}" 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 vThat 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:
[Parameter(Mandatory)]
[ValidateRange(1, 20)]
[int]$foo
That's it, the entire thing, done.I use pwsh on Linux every day.
Anything that isn't a lisp machine is a legacy OS ;-)
I realise I've given offense, for which I'm sorry, but I'm driven not so much to denigrate bash as to advocate for a world where shells are semantic.
Syntactically I'd even prefer a single line, like
[Pram(musthave):In(1, 20)/"Foos excessive or inadequate":int/$foo:"Foo count"/"Please supply how many foos you want."]