The role of small and medium parentheses bash

Single parentheses ()

  ① command group. Brackets command will open a new sub-order execution shell, so parentheses variables can not be part of the rest of the script to use. Multiple commands brackets separated by a semicolon, the last command can no semicolon, do not have a space between the command and the bracket.

  ② command substitution. Equivalent to `cmd`, shell command line scanning again found cmd execution $ (cmd) structure, put $ (cmd) in the first, to obtain its standard output, then this output into the original order. Some shell does not support, such as tcsh.

  ③ is used to initialize an array. Such as: array = (abcd)

The latter two cases is easier to understand; the first case, seen following script:

[root@localhost html]# cat makerepo.sh 
#!/bin/bash
cd /usr/share/nginx/html/repo
for i in e2fsprogs-wc lustre-client lustre-server patchless-ldiskfs; do
    (cd $i && createrepo .)
done

among them 

(cd $i && createrepo .)

Equivalent to:

cd $i && createrepo . && cd -

Reference links:

https://www.jb51.net/article/123081.htm 

Stay updated, if helpful to you, please click on the recommendation!

Guess you like

Origin www.cnblogs.com/xuyaowen/p/bash-brackets.html