Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16529

Return from function depending on number of parameters

From Chris Elvidge <celvidge001@gmail.com>
Newsgroups gnu.bash.bug
Subject Return from function depending on number of parameters
Date 2020-07-03 19:00 +0100
Message-ID <mailman.906.1593807689.2574.bug-bash@gnu.org> (permalink)
References <b1c19d38-64c0-f1ae-d08a-1ada435a0022@gmail.com>

Show all headers | View raw


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

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Return from function depending on number of parameters Chris Elvidge <celvidge001@gmail.com> - 2020-07-03 19:00 +0100

csiph-web