bug-bash
[Top][All Lists]
Advanced

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

Re: Bash style of if-then-else?


From: Marc Herbert
Subject: Re: Bash style of if-then-else?
Date: Fri, 24 Sep 2010 09:22:50 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100907 Fedora/3.1.3-1.fc13 Thunderbird/3.1.3

> On Thu, Sep 23, 2010 at 04:38:42PM -0500, Michael Witten wrote:
>> This is also possible:
>>
>>   [ -f "$file" ] && do_something

Note that this style is not compatible with set -e


Le 24/09/2010 00:35, Ken Irving a écrit :
> While we're talking about style...  I prefer using 'test' rather than
> '[..]' as it seems to me to be more readable.
> 
> Are there actual advantages for [] over test?  I guess the former uses
> one less byte than the latter.

For longer conditions brackets are easier to "parse"; the reader has no
doubt where it ends.

By the way I wonder if this makes any difference to the actual parser.

On the other hand some people explain that long conditions are bad
practice anyway, and that you should write:

     test x && test y || test z





reply via email to

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