Shell Quoting. Was: Shell tips and tricks

Ben Scott dragonhawk at gmail.com
Tue Oct 9 13:02:37 EDT 2007


On 10/8/07, Steven W. Orr <steveo at syslang.net> wrote:
> if [[ blah1 && blah2 ]]
> otherwise you'd have to say
> if [ blah1 ]] && [ blah2 ]
> which I'm hoping won't generate a different set of questions.

  (I'm assuming, in the second example, the doubled
right-square-bracket after "blah1" is a typo.)

  Can't you just say

	[ blah1 -a blah2 ]

for the second one?  That's what I've always done.  I supposed,
aesthetically, one might prefer the use of && over -a because it looks
more like C or makes one think of "and" or whatever, but beauty is in
the eye of the beholder and all that.

  So I'm not really getting blown away by the practical difference
between [[ ... ]] and [ ... ] here.  Is there something I'm missing?

> The history is that before [ was a builtin, it used to be an external
> program. You could look on old unix boxen and there'd be a file called
> test which had a hard link to a file called [.

  /usr/bin/[ still exists every time I've looked, but interestingly,
it's not the same thing on my Fedora 6 box:

blackfire$ cmp /usr/bin/test /usr/bin/[
/usr/bin/test /usr/bin/[ differ: byte 25, line 1

-- Ben


More information about the gnhlug-discuss mailing list