Monday, January 17, 2011

UNIX : The difference between [ ... ] and [[ ... ]] (The extended test operator)

The [[...]] is processed as part of the shell grammar whereas [...] is processed like any other command.
Operators and operands are detected when the command is read, not after expansions are performed. 
 
  1. The shell does not do word splitting or path-name generation inside [[...]].This allows patterns to be specified for 
    string matching purposes.
  2. Parameter expansion and command substitution is allowed.
  3. Prevents many logic errors in scripts. e.g [ "$x" = "TEST" ] can be written as [[ $x = "TEST" ]] the variables don't need to be quoted.
  4. The &&, ||, <, and > operators work within a [[ ]] test, despite giving an error within a [ ] construct.

No comments:

A TRIP TO BHANDUP PUMPING STATION - the birdwatchers paradise

"A Picture from Bhandup Pumping Station" I am a nature lover, and I often like to go birdwatching with my dad. We had read that &q...