I've used 'return $((!$#))' and 'return $[!$#]' to return an error if no parameters given to function.

Tested in a bash script 'exit $((!$#)) / $[!$#]' - both work.

'echo $((!$#)) / $[!$#]' - both echo 1 when no params, 0 when any number of params.

I'm told ( https://wiki.bash-hackers.org/scripting/obsolete ) that $[...] is obsolete and that $((...)) should be used instead. OK so far.

However 'N=0; echo $((!$N))' gives an error at the bash prompt. 'echo $[!$N]' echo's 1 as expected.

My question - is $[...] actually obsolete? If so, what should I use at the bash prompt to get the same effect?

Cheers



--

Chris Elvidge

Reply via email to