Вопрос

It is confusing me when I see some bracket and comma show on the script. I can't really understand how does it make it. For example

find /work \( -fprint /dev/stderr \) , \( -name 'core' -exec rm {} \; \)

Question:- -what does bracket do? -what does comma do? -where can I get this manual about bracket and comma keyword in bash.

Это было полезно?

Решение

The parentheses/brackets are used by find to enforce precedence among its predicates. The comma is an operator in GNU find that evaluates both the preceding predicate and the predicate that follows, but ignores the result of the first. In your command

find /work \( -fprint /dev/stderr \) , \( -name 'core' -exec rm {} \; \)

you have two (compound) predicates:

  • -fprintf /dev/stderr
  • -name 'core' -exec rm {} \;

The first one prints the name of the found file to standard error. The second one removes only those files whose name is core. Without the comma, only the names of the file being removed would be written to standard output; that is, the comma overrides the implicit and performed on multiple predicates. (The parentheses around the -fprintf might be optional, since they are just forming a group consisting of a single predicate, but I'm not positive.)

Другие советы

( and ) are used in bash to execute one or more commands in a sub-shell. You can find more on that topic at http://www.tldp.org/LDP/abs/html/subshells.html.

However, in the command that you have posted, they are not used by bash since they are escaped -- you are using \( instead of just (. As a result, ( and ) are passed to find as its arguments. Also note that ; is also escaped since it has special meaning in bash. As far as find is concerned, it sees the following arguments:

/work ( -fprint /dev/stderr ) , ( -name 'core' -exec rm {} ; )

The comma (,) is part of the find command. bash does nothing with it.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top