[18699] in Athena Bugs

home help back first fref pref prev next nref lref last post

Re: Bash init files suggestion

daemon@ATHENA.MIT.EDU (Stephen Gildea)
Fri Jan 26 16:49:08 2001

Message-Id: <200101262149.QAA27642@mass-toolpike.mit.edu>
To: Kev <klmitch@MIT.EDU>
cc: bugs@MIT.EDU, gildea@MIT.EDU
In-Reply-To: Message from klmitch@MIT.EDU of 26 Jan 2001 13:55:41 EST
    <200101261855.NAA09252@multics.mit.edu> 
Date: Fri, 26 Jan 2001 16:49:03 -0500
From: Stephen Gildea <gildea@MIT.EDU>

>   Imagine TERM=-e, as suggested; then that expands to [ ! -e ].  The way
>   this is often tested is [ "x$TERM" != x ]--the "x" prevents things
>   starting with "-" from being interpreted as arguments to test.

I am aware of the traditional problem with terms starting with a
hyphen.  The POSIX spec fixes this by specifying that "test" look at
the number of arguments it is given, and from that deduce where the
terms must be, and don't treat them as operators, even if they begin
with a hyphen.

Try it yourself with Bash:
    test ! -e && echo true
works as expected.  (Traditional "test" will give an error message
about a missing argument to "-e".)

To make argument counting work, POSIX removed support for the -a
("and") and -o ("or") operators.  You should now use separate tests
connected with && or || like this:

if [ "$file" ] && [ -r "$file" ]; then ...

home help back first fref pref prev next nref lref last post