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

Re: Help with the /etc/init.d/network




"A. Scott White" wrote:
> 
> Can anyone tell me exactly what this line accomplishes:
> 
> [ "${GATEWAY}" ] && route add default gw ${GATEWAY} metric 1

if the $GATEWAY variable has been set, run the command 'route add
default gw ${GATEWAY} metric 1.

The [ and ] are synonyms for the 'test' program. In this case, if
$GATEWAY is set, test returns 1, otherwise it returns 0. The return
value from test determines whether the rest of the line is executed,
because of the && (logical AND). The commands on this line are executed
left to right. However, if the first (the test) results in 0, then the
result of the logical AND can never be 1, so the second command is not
executed -- it works like an if statement basically.

Matthew



Reply to: