Skip site navigation (1) Skip section navigation (2)

Re: When scripting, which is better?

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Justin Clift <justin(at)postgresql(dot)org>
Cc: PostgreSQL Hackers Mailing List <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: When scripting, which is better?
Date: 2001-10-02 18:53:48
Message-ID: Pine.LNX.4.30.0110022035210.796-100000@peter.localdomain (view raw or flat)
Thread:
Lists: pgsql-hackers
Justin Clift writes:

> i.e.  if [ -x "$self_path/postmaster" ] && [ -x "$self_path/psql" ];
> then
>
> or
>
> if [[ -x "$self_path/postmaster" && -x "$self_path/psql" ]]; then

I don't think the second one is a valid expression. ;-)

Maybe you were wondering about [[ ]] vs [] -- In Autoconf [] are the quote
characters so you have to double-quote, sort of.  It's better to use
'test' in that case because m4 quoting can be tricky.  I prefer test over
[] in general because it is more consistent and slightly clearer.

> if [ x"$foo" = x"" ]; then

Maximum safety for the case where $foo starts with a dash.  Yes, that
means all comparisons should really be done that way.  No, I don't think
we should do it in all cases if we know what $foo can contain, because
that makes code *really* unreadable.

> or
>
> if [ "$op" = "" ]; then
>
> or
>
> if [ "$foo" ]; then

These two are equivalent but the second one is arguably less clear.

-- 
Peter Eisentraut   peter_e(at)gmx(dot)net   http://funkturm.homeip.net/~peter


In response to

pgsql-hackers by date

Next:From: Peter EisentrautDate: 2001-10-02 19:03:40
Subject: Re: CVS changes
Previous:From: Tom LaneDate: 2001-10-02 18:08:47
Subject: Re: Unicode combining characters

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group