Shell Quoting. Was: Shell tips and tricks

Steven W. Orr steveo at syslang.net
Mon Oct 8 14:39:30 EDT 2007


On Monday, Oct 8th 2007 at 14:07 -0000, quoth Tom Buskey:

=>On a similar note, why would you use [[...]] instead of [...] ?
=>

Lots of reasons. [ is a builtin function. [[ is a keyword.

524 > whatis [
builtin [
*525 > whatis [[
-bash: ${[[+set}: bad substitution
whatis: [[: not found

Don't switch because [[ is faster because it is but not by much. [[ gives 
better syntax.

if [[ blah1 && blah2 ]]
otherwise you'd have to say
if [ blah1 ]] && [ blah2 ]
which I'm hoping won't generate a different set of questions.

So && and || are used to connect statements but within [[ it is used as 
conjunctions.

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 [. The ] at the end of the [ 
was just syntactic sugar. There's no difference between

if test blah1again
and 
if [ blah1again ]

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net


More information about the gnhlug-discuss mailing list