Re: bash vs. python scripts - which one is better?
On 2007-08-19 21:23:12 -0600, Bob Proulx wrote:
> Manon Metten wrote:
> > David Brodbeck wrote:
> > > It certainly has its warts. In particular, Bash's "test" (aka "[")
> > > operator has pitfalls.
>
> The test command was originally not a shell built-in. It was an
> external standalong /bin/test command. For performance reasons it has
I don't think it is for performance reasons. Have you ever seen any
noticeable performance gain?
> been incorporated into the shell but the interface can't change or it
> would break compatibility.
Sure:
vin:~> bash
vlefevre@vin:~$ touch exists
vlefevre@vin:~$ [ ! -a exists ] || echo found
vlefevre@vin:~$ /usr/bin/[ ! -a exists ] || echo found
found
vlefevre@vin:~$
I think that [ has been added as a builtin to the bash shell in order
to add features... that break compatibility!
> But better to use the one = so that it is portable. I prefer using an
> underscore to hide it more but 'X' is the tradition.
>
> if [ _"$foo" = _"" ]
Are you sure that
[ "$foo" = "" ]
isn't POSIX sh? IMHO, it is perfectly valid (note: the quotes are
important).
--
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)
Reply to: