[Techtalk] Shell scripting for newbies
Conor Daly
conor.daly at oceanfree.net
Sat Feb 21 10:52:25 EST 2004
On Thu, Feb 19, 2004 at 05:25:30PM -0800 or so it is rumoured hereabouts,
Kai MacTane thought:
>
> >url=$1; [ -z $url ] && url=about:blank
>
> After the semicolon, we have a test (the part in square brackets). The
> square brackets themselves tell bash to treat their contents as something
> to be tested for truth or falsehood.
To be a bit pedantic on this, the first bracket '[' is a symlink to the
program 'test' which expects a ']' as its last argument when called as
'['. You can also run 'test' in the same fashion with no closing ']'.
AIUI, the '[ .. ]' invocation was designed to look 'natural' in an
'if-then' clause thus:
if [ -z $url ]; then
....
fi
while the quoted construct above could be written:
test -z $url && url=about:blank
though it appears lately that people are using [...] instead which is a
little harder for a novice bash reader to understand.
Note than 'man [' gives 'No manual entry for [' while 'man test' gives the
manpage and all the switches!!
Conor
--
Conor Daly <conor.daly at oceanfree.net>
Domestic Sysadmin :-)
---------------------
Faenor.cod.ie
9:50am up 121 days, 2:59, 0 users, load average: 0.00, 0.06, 0.06
Hobbiton.cod.ie
9:44am up 121 days, 2:47, 1 user, load average: 0.00, 0.03, 0.00
More information about the Techtalk
mailing list