S7_0
S7_0

Reputation: 1183

Precedence of shell operator

I'm currently trying to re-code a shell in C using a BNF and LL parser. Otherwise, I need to know what is the precedence of shell operator of |, <<, ,, <, >>, >, &, ;?

Is there anyone who can provide me it ? Thank you

Upvotes: 7

Views: 5116

Answers (1)

rici
rici

Reputation: 241911

  1. Redirections (<, >, >>, <>, <&. >& and >>-, as well as here-docs <<delimiter and here-strings <<<word) are roughly the same as command-line arguments, and can appear anywhere in a simple command, including before the command word. Effectively, they bind most tightly, as with postfix operators in most languages.
  2. Pipes (|) are the strongest binary operator. They associate to the left.
  3. Finally come the short-circuiting booleans (&& and ||). Unlike many languages, these have the same precedence. They also associate to the left.

, is not a bash operator. ; and & are statement terminators, not separators, although in some circumstances the final separator is optional. Effectively, they have the lowest precedence.

See the shell grammar for details. There are lots of details.

Upvotes: 15

Related Questions