Using parenthesis to group and expand expressions

Grouping a (list of commands) in parenthesis causes them to be executed as if they were a single unit.


Group commands in a sub-shell: ( )

  ( list )
Placing a list of commands between parentheses causes a subshell to be created, and each of the commands in list to be executed in that subshell. Since the list is executed in a subshell, variable assignments do not remain in effect after the subshell completes.

Group commands in the current shell: { }
  { list; }

In addition to the creation of a subshell, there is a subtle difference between these two constructs due to historical reasons. The braces are reserved words, so they must be separated from the list by blanks. The parentheses are operators, and are recognized as separate tokens by the shell even if they are not separated from the list by whitespace.


Return a binary result of expression: [[ ]]

   [[ expression ]] 

Return a status of 0 or 1 depending on the evaluation of the conditional expression. Word splitting and filename expansion are not performed on the words between the [[ and ]]; tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, process substitution, and quote removal are performed.

When the == and != operators are used, pattern matching will be done on the string to the right of the operator.
The return value is 0 if the string matches or does not match the pattern, respectively, and 1 otherwise.


Expressions within the [[ ]] may be combined using the following operators, listed in decreasing order of precedence:

( expression )               Returns the value of expression.
This may be used to override the normal precedence of operators. 

! expression True if expression is false.
expression1 && expression2 True if both expression1 and expression2 are true.
expression1 || expression2 True if either expression1 or expression2 is true.

The && and || commands do not execute expression2 if the value of expression1 is sufficient to determine the return value of the entire conditional expression.

Arithmetic expansion


$(( expression ))


If the expression is invalid, Bash prints a message indicating failure to the standard error and no substitution occurs.


Bash Syntax

© Copyright 1999-2014
Some rights reserved