On Sat, 2008-05-17 at 15:52 +0200, Bastian Bittorf wrote:
> 
> Do you think so? I believe that it is better readable

I've programmed I don't want to think how many thousands or tens of
thousands of lines of shell script, so I think I'm pretty familiar with
readability and lining up = signs doesn't help.  I guess we will just
have to agree to disagree.

> > Use the || short-circuit syntax:
> > 
> >     ifconfig $DEVICE $IP netmask $NETMASK broadcast $BROADCAST up || {
> >             # ifconfig failed -> fallback to using ip
> >             ip addr add dev $DEVICE $IP/$CIDR_MASK broadcast $BROADCAST
> >             ip link set dev $DEVICE arp on  
> >             ip link set dev $DEVICE up
> >     }
> 
> Not very nice, especially on large conditions.

What do you mean?  Can you give an example?  I find the above to be very
succinct, efficient and obvious.  There are pitfalls with your approach
(lines numbered for subsequent comment):

1.  <command>
2.
3.  if [ $? != 0 ]; then
4.      <other_command>
5.  fi
6.

The pitfalls are:

     1. if somebody adds code before line 3, the test is invalid
     2. if somebody turns line 1 into a pipeline, $? no longer tests the
        success of <command> but whatever was at the end of the pipeline
     3. efficiency: requires a call to "test" ([) to determine if
        fallback should be taken

But I won't beat a dead horse.  If you still want to do it with if and a
test, I'm probably not going to change your mind.

b.

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
openwrt-devel mailing list
[email protected]
http://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to