7

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

phuclv
  • 37,963
  • 15
  • 156
  • 475
S7_0
  • 1,165
  • 3
  • 19
  • 32
  • This is not related to C – too honest for this site Aug 09 '15 at 13:48
  • Yes but what ever the langage that you use when you want to code a shell You need to know the precedence of the shell operator – S7_0 Aug 09 '15 at 13:50
  • That is no contradiction to what I wrote. The question is about shell, not the implementation language. And as you do not even mention the shell ... What have you done yourself to find the answer? But, yes it is certainly easier to ask instead of just googling or searching the man-page. – too honest for this site Aug 09 '15 at 13:53
  • I see that I can perform math operations on Bash shell variables using this order of precedence | & << < >> > But I don't find the semi colon caractere and I'm not sure if it work by the same way for a shell command line – S7_0 Aug 09 '15 at 14:14
  • 1
    Here is the [shell grammar specification](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02) – that other guy Aug 09 '15 at 15:24

1 Answers1

14
  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.

rici
  • 234,347
  • 28
  • 237
  • 341