Path: csiph.com!xmission!feeder.erje.net!us.feeder.erje.net!nntp.club.cc.cmu.edu!169.228.66.3.MISMATCH!ihnp4.UCSD.Edu!usenet.stanford.edu!not-for-mail From: Eric Blake Newsgroups: gnu.bash.bug Subject: Re: Function name conflict with alias in bash-4.3 Date: Tue, 25 Aug 2015 14:39:26 -0600 Organization: Red Hat, Inc. Lines: 87 Approved: bug-bash@gnu.org Message-ID: References: <55DC9992.8070209@pom-monitoring.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="xd32hUgD1x86CaxA2GPV9hjFJb74GfxEs" X-Trace: usenet.stanford.edu 1440535178 14270 208.118.235.17 (25 Aug 2015 20:39:38 GMT) X-Complaints-To: action@cs.stanford.edu To: Corentin Peuvrel , bug-bash@gnu.org Envelope-to: bug-bash@gnu.org Openpgp: url=http://people.redhat.com/eblake/eblake.gpg X-Enigmail-Draft-Status: N1110 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 In-Reply-To: <55DC9992.8070209@pom-monitoring.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11442 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --xd32hUgD1x86CaxA2GPV9hjFJb74GfxEs Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 08/25/2015 10:36 AM, Corentin Peuvrel wrote: > Hi, >=20 > I found a bug in bash-4.3 (4.3.39 in fedora 21), that seems to exists f= or a long time (at least from 4.1.2 in Centos 6). Not a bug, but a misunderstanding on your part about how aliases work. Alias expansion is done on the left-most word PRIOR to anything else; and if the alias itself expands with a trailing space, then it is also applied to the next word in turn. But subsequent words are NOT considered for alias expansion unless the earlier words followed that rul= e. >=20 > If you have an alias named "foobar", you can create a function with the= keyword "function" (with or without parenthesis) : > $ function foobar { :; } Yes, this is using deprecated syntax (these days, it is more portable to declare functions without using the 'function' keyword). And because you don't have: alias function=3D'function ' defined, alias expansion stops as soon as 'function' is encountered, and 'foobar' cannot be treated as a potential alias needing expansion. >=20 > But you cannot if you don't : > $ foobar() {:;} > -bash: syntax error near unexpected token `(' Here, alias expansion sees 'foobar' as a potential word needing expansion, so it expands it. And whatever you have it aliased to is then causing a syntax error when bash then goes to parse the resulting li= ne. Normally, you can force alias non-expansion with strategic quoting, but in the case of declaring a function, any quoting you add would render first word invalid as a function name and therefore also cause problems. Nothing we can do about it, as it is not a bug, but a documented design consideration. >=20 > It's not really critical once you know it, but it's a little bit odd != And while there are one or two legitimate reasons for aliases to still exist (there are some effects that HAVE to be done prior to parse time, and cannot be deferred to a function, such as temporarily disabling globbing for the duration of a parse), you have just (re-)discovered one of the reasons why we strongly recommend the use of functions rather than aliases in the majority of modern code. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --xd32hUgD1x86CaxA2GPV9hjFJb74GfxEs Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJV3NJ+AAoJEKeha0olJ0NqinoIAI387bhzaGJuMFekthybDF6S w2OMDDQbDV131vtOEMOkVih0NMOh+7Ex0/uHwLnXUWaWACdIpN6PSLM5A/prKvvS XLiGipaaV3z3yA5JLv4dg+ycjRATO3/9NqkMyvjYCt88/VDcFQr8Asl2o8Wnz3IB JMSY2pPhFbM49/SB6aBzCPXZENd3hn+HdUflD1bdQO5dWE4z8Wd1wP0q6XDz87Gs LNs04lJ9VJeygKJt34/i6z2mW/5HXWZq4Y3oMAPmP/I/sdhI2HBKxJqEyiSdjk0o blwN7ZmIM46SOJPciEo+Z+eGajnMQAUrJZslmt/qg9U1f2eikbt71f5Niv3M9QY= =FHaN -----END PGP SIGNATURE----- --xd32hUgD1x86CaxA2GPV9hjFJb74GfxEs--