bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: style of assignment to variable changes command selection


From: Eric Blake
Subject: Re: style of assignment to variable changes command selection
Date: Fri, 07 Mar 2008 20:37:54 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080213 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Doug McIlroy on 3/7/2008 7:17 PM:
| These two bash sequences are not equivalent.
| My intuition and the bash man page tell me they should be the same.
|
|   % export X=x; time --version; unset X
|   -bash: --version: command not found
|
|   % unset X; X=x time --version
|   GNU time 1.7

Thanks for the report.  However, I don't think this is a bug.  On many
platforms, time is both a bash reserved word, as well as a binary
application.  POSIX states this as an informative note:

"In the KornShell, time is a shell reserved word that can be used to time
an entire pipeline, rather than just a simple command. The POSIX
definition has been worded to allow this implementation."

The difference in behavior is because this is the implementation that bash
chose - unlike all other bash builtins (which are not reserved words),
time is recognized as the bash version ONLY if it is the first word of a
simple command; using a variable assignment bypasses the reserved word
recognition and defers to the binary application.

Try these
unset X; time X=x --version
export X=x; /bin/time --version; unset X

for comparison.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFH0goS84KuGfSFAYARAiXJAKDCwLAGNxEReoh3cnFufAeZLnQT6ACgxexq
MBpXAs0R5DQ3+EFaSH/Hkc0=
=nb0e
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]