[Top][All Lists]

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

Return / exit values

From: Chris Elvidge
Subject: Return / exit values
Date: Thu, 10 Sep 2020 00:10:00 -0000
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

I've used 'return $((!$#))' and/or '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 ( ) 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?


reply via email to

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