[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
$[...] or $((...))
From: |
Chris Elvidge |
Subject: |
$[...] or $((...)) |
Date: |
Thu, 10 Sep 2020 00:10:03 -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 '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
England
- $[...] or $((...)),
Chris Elvidge <=