Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Eli Schwartz Newsgroups: gnu.bash.bug Subject: Re: Return from function depending on number of parameters Date: Sat, 4 Jul 2020 23:35:57 -0400 Lines: 131 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: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="3JfJBiAxK4ZFqZ9fUTMIO1MTXjNrWjlSx" X-Trace: usenet.stanford.edu 1593920180 15189 209.51.188.17 (5 Jul 2020 03:36:20 GMT) X-Complaints-To: action@cs.stanford.edu To: Chris Elvidge , bug-bash@gnu.org Envelope-to: bug-bash@gnu.org X-Spam-BL-Results: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1593920162; bh=By8qHi45aGa6R0xI+wxt0Tv+N1gPc5/5kMWkB57nR50=; h=Subject:To:References:From:Date:In-Reply-To; b=N8d6VlCh6gHPfIvZlQq1moaDiqLLL8vOOTNanRaD3NBg/zqBVg9kSJhozgbOGt0Mh 2wd2ODME+G6fhNNCh0XCMG1Xo2HP91/IB4hZhezmjcRqHro441qoZARvKE6vSuyZmk kkVwazTSujt0UQ1O7diLmcTMGqekWm7uHzTwdZpik4Qjl9SEcb7Ldz2auJ0zzsJgcy 4EH/37kWjpReTpj8qUr6q7MP8IEXjNlFR1+3WB3PH8Z884Gl3+PfxLuhUarP47ZmG0 /n6C99UluoKT4dTHC/6ypo8/tIkck+5jc70zOECQQL2/VpW9w2/duDtcTsO9SkR8V4 VTrmUVdtkuEajNHHQKj+pqnPLUlfbFn53Q0bGF3DLx5yftuSarygM0PPRoyQ4as1nk Nrg0fL3ELYFgLKrOksirf8eVr1eD5S/h6BtrP/bPVySAzc9OeBOGeSCs/MzQBwSW8K efJ65GKmXMuw44r2BkjyOI07rRUn+VVvYR26nCHJGUQlraC28cgR8mmUb52v2WZcI0 So5C7Qsaj8aNByr5OhWxPg05tSCyGrvDfl7MgAmrxbaBKFU9EK3BCVb8IktWbQmyMv Als6s/fVfiPVSQMI1gcry4YDHMhzikM/bowZMMtsM9mzCSZVvx38EgIwaCbsVE64a4 v5EvYxvJjVx3MLz06uKAmnLc= X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 In-Reply-To: <73b2d4c9-badf-e059-3a77-57d2f9ef197b@gmail.com> Received-SPF: pass client-ip=88.198.91.70; envelope-from=eschwartz@archlinux.org; helo=orion.archlinux.org X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/04 23:36:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: X-Mailman-Original-References: <4766f763-84b7-f018-f925-7c6390ed7523@archlinux.org> <73b2d4c9-badf-e059-3a77-57d2f9ef197b@gmail.com> Xref: csiph.com gnu.bash.bug:16540 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --3JfJBiAxK4ZFqZ9fUTMIO1MTXjNrWjlSx Content-Type: multipart/mixed; boundary="0GbpBJw7iJXIh1WBerE91oABahmwT8l44" --0GbpBJw7iJXIh1WBerE91oABahmwT8l44 Content-Type: text/plain; charset=utf-8 Content-Language: en-US-large Content-Transfer-Encoding: quoted-printable On 7/4/20 7:54 AM, Chris Elvidge wrote: > 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=C2=A0 $((!$#)) / $[!$#]' - both echo 1 when no params, 0 when a= ny >>> number of params. >>> >>> I'm told ( https://wiki.bash-hackers.org/scripting/obsolete ) that >>> $[...] is obsolete and that $((...)) should be used instead. OK so fa= r. >>> >>> However 'N=3D0; echo $((!$N))' gives an error at the bash prompt. 'ec= ho >>> $[!$N]' echo's 1 as expected. >> >> "gives an error" is a useless bug report. It works for me. >> >> $ N=3D0; 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=3D0; echo $((!$N)) >> N=3D0; echo $((histexpandN)) >> 0 >> $ N=3D0; echo $((!$N)) >> N=3D0; echo $(()N)) >> -bash: syntax error near unexpected token `)' >> $ N=3D0 >> $ echo $((!$N)) >> echo $((N=3D0N)) >> -bash: N=3D0N: value too great for base (error token is "0N") >> >> ... >> >> =C2=A0From there, people can give useful advice for solving the proble= m. (My >> preferred advice is "disable histexpand".) >> >=20 > 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. It's the section "HISTORY EXPANSION", and set -o histexpand is equivalent to set -H, which controls this option. Many people first realize it exists only when they've been bitten by it. = :) > Did you mean set +o histexpand to disable the feature? "set +o histexpand" is in my bashrc to disable the feature. "set -o histexpand" is what I used at the console to temporarily re-enable it, in order to reproduce your issue. As you can see from $ N=3D0; echo $((!$N)) N=3D0; echo $((histexpandN)) 0 the first history expansion inserted the word "histexpand" into my command, because the previous command used the word. --=20 Eli Schwartz Arch Linux Bug Wrangler and Trusted User --0GbpBJw7iJXIh1WBerE91oABahmwT8l44-- --3JfJBiAxK4ZFqZ9fUTMIO1MTXjNrWjlSx Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEvSewel70XCra9w4EhIGKaBmvSpsFAl8BSp0ACgkQhIGKaBmv SpujUhAAldTcUEpBV5l9dOS5NEx6s4gIKauhze+GtL8BkxJkN/Lcafd2Lr1dQ3Dv GgvpNHAV641NpMZ5UVnPTZD/pqgJ1/Qg4WmkBUiDzw3AMr3nhazJsiHLkkQuC20K NSeRAMEYvXeMt/VGfbvt2aNqUnegHGmKbPXqM29GOWEI2GBRj9oxl2vjC3jTq0c2 jfAmWyQQ+b2i4PglHXYHqvdRWBep8ZHBt/Ji+BxQje2FWsWvqSeGIZ/75irk1Tov fRnMQNUS3/jouOYNYQWfUN14Y6cQNaQM1DrSEMQc+VpOothnWACqpz1/gmfYczQR tq1TauimFt5f/yU3Sx4ZpZ2acBoWbTRijZYFlE5Hyy6mXcoFTmCUO2pZu0UWvXbt sjoJcvgDgPJ/cwvEsr7k8TLd7YcyagsMg0H8y5TXNXLeB0tUmLFJvJhgORS1R2w5 WT+wQPEV7kJB/4NYNSz1ptbt7ecXcs/eopaafLCE/Yu93mPm1SuCNLENb8+bBmtH KfWDEGYjTk8HxiKDg/S46cyGjZANYm+4QfJ45czX11RfLbzxrTgvgAQMf26M7Nqr Wdji3ajWJpvQaf0KAcesJuFw5XTjsEiSvyhYA5mh6yNk89t6l3LH1EMCWjabj599 WQMcCa5s7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