Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Chris Elvidge Newsgroups: gnu.bash.bug Subject: Re: Return from function depending on number of parameters Date: Sat, 4 Jul 2020 12:54:03 +0100 Lines: 61 Approved: bug-bash@gnu.org Message-ID: References: <4766f763-84b7-f018-f925-7c6390ed7523@archlinux.org> <73b2d4c9-badf-e059-3a77-57d2f9ef197b@gmail.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1593863651 12433 209.51.188.17 (4 Jul 2020 11:54:11 GMT) X-Complaints-To: action@cs.stanford.edu To: Eli Schwartz , bug-bash@gnu.org Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=E5u0KVav3sV3Vi1OdONBAtuuDVw9QOW0c+/wx54HayA=; b=UIJ+IIS6IXatLCfuhFppz6tgvZVt5fNVXjf+pPSttdZ9l1eJpeYyTUYb5uc86imLUs zE4RiPDTfw7uNUX3m75Eeg357Ftt1N7X53vZULsM/KuC6DXbYLnXi943OTDHqqJ1Ua+W FP/j4vecKQO67nJgTDCcNg2nREhiaHgw5e6I/7IGDax6qvSvtSPWZk5VKTbT2FDdN7Kq mYcRh3RRFxs2kisKrim7t5R3aDJIueUPf0OLxz6zFtq7CHHFi7DXfz/EkQEUeeU5p5PG Yr2HAYVDVqduPpfZFvgykQ3BFuQ8BgQCCgvDZcEP3rzNNyt/VJq/tmain7KkxSoJ/QrD qPbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=E5u0KVav3sV3Vi1OdONBAtuuDVw9QOW0c+/wx54HayA=; b=MZJGOa5wlx012bJcc+R3yrrQAIsgDrEuLlIFP08g7JftA28EtDCtRdrT2W3Cp5R4x8 URCPMqpgDQC+m85TQj8OOr3wZwlyKIxRX5bn/lOKD+i+NpxdQ2r00PbSVe7RQvyYDjBU OzQjfzwOi+W6ZGxgCISumfu9RjvY8XRg6sCSbWSQAi2kHFDLZUoGIRAl3rC/hydp2biJ i1UNX9dW1yELvHoD0k68J7af8sYdekplg6AXpLA/3FSq3ls+bPVx/PFw4EpQwixl4sQJ H+zTx8retQ4ud5BYw7N9Pn0yN+FdGILHfg3UhYqTianpbKFWiAvRKexZgPzrNS+cDhD0 eq7g== X-Gm-Message-State: AOAM530Ee6BNMnV+ifyf6g+pitIC+EXJcFrQ4INgtebt33RieAIQwZqt h23mKrSYSnNqtipGMzXuObXCAvHm5Wo= X-Google-Smtp-Source: ABdhPJyyGD3/XpEfzo3iVjNwnBDCKM6F2gRFmbl3s1BwUVduYNBiJ2LeLVVHUnLsnbAbogrql+hOXQ== X-Received: by 2002:a1c:f301:: with SMTP id q1mr40628292wmq.110.1593863646268; Sat, 04 Jul 2020 04:54:06 -0700 (PDT) User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: <4766f763-84b7-f018-f925-7c6390ed7523@archlinux.org> Content-Language: en-GB Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=celvidge001@gmail.com; helo=mail-wm1-x32b.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <73b2d4c9-badf-e059-3a77-57d2f9ef197b@gmail.com> X-Mailman-Original-References: <4766f763-84b7-f018-f925-7c6390ed7523@archlinux.org> Xref: csiph.com gnu.bash.bug:16533 On 03/07/2020 11:16 pm, Eli Schwartz wrote: > On 7/3/20 2:00 PM, Chris Elvidge wrote: >> 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. > > "gives an error" is a useless bug report. It works for me. > > $ N=0; echo $((!$N)) > 1 > > My initial reaction to reading this thread is head scratching! > > As the other reply mentioned, there's actually a good explanation for > why we get different results -- I disabled an annoying feature. > > $ set -o histexpand > > Now here's a useful bug report. "When I run this, I get the following > incorrect results or error message": > > $ N=0; echo $((!$N)) > N=0; echo $((histexpandN)) > 0 > $ N=0; echo $((!$N)) > N=0; echo $(()N)) > -bash: syntax error near unexpected token `)' > $ N=0 > $ echo $((!$N)) > echo $((N=0N)) > -bash: N=0N: value too great for base (error token is "0N") > > ... > > From there, people can give useful advice for solving the problem. (My > preferred advice is "disable histexpand".) > Thanks for the pointers to a better bug report. And thanks for the info on histexpand. I obviously should read the manual more carefully - I'd never come across it - as it's set by default, not in any profile or bashrc file. Did you mean set +o histexpand to disable the feature? -- Chris Elvidge