bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Return from function depending on number of parameters


From: Chris Elvidge
Subject: Return from function depending on number of parameters
Date: Fri, 3 Jul 2020 19:00:54 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

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

[Prev in Thread] Current Thread [Next in Thread]