[Skip Navigation] [Remove Frame] [CS320] [Text Version] shell.syntax.html Sat Dec 23 08:00:46 PST 2006

Contents


    [ /u/faculty/dick/cs320/math.comp.ascii ]
  1. |- white_space::= SP | HT | ...
  2. doublequote::="\"", quote:="'", backquote::="`", backslash::="\\".

    SYNTAX

    The Bourne shell a pure interpreter for a highly interactive, complex and powerful programming language with syntax based loosely on ALGOL 68. The basic input (from a user or from a file) into the interpreter (sh) is a sequence of pipelined commands.

  3. pipeline::= command (input_redirection|) #("|" command) ("|" command output_redirction|).

  4. input_redirection::= "<" file | "<<"string.
  5. output_redirection::=( ">" | ">>" ) file.

  6. command::=command_name #(separator argument), Normally, separator::=whitespace #whitespace.

  7. argument::=#(word | string | escaped_symbol ),
  8. word::=#(value_shell_variable| value_of_argument | #(char~separator)),

    A script is a sequence of commands and control structures separated by command separators

  9. script::=(command | built_in_structure) #(command_separator (command | built_in_structure)),
  10. command_separator::=EOLN #whitespace | semicolon #whitspace.

  11. built_in_structure::=assignment | selection | loop | other_command,
  12. selection::=if_then_fi | case_esac,
  13. loop::= for_do_done | while_do_done | ... .
  14. other_command::=exit_statement | echo_statement |... .

    A shell variable is identified by an identifier:

  15. shell_variable::=identifier,
  16. value_of_variable::= "$" variable| "${" identifier operator word "}",
  17. The "${...}" form is left undefined.

    Arguments are numbered inside a shell script:

  18. script_argument::= digit,
  19. value_of_argument::="$"digit.

    There are several special variables/values:

  20. value::=value_of_argument | value_of_variable | "$" ( "$" | "?" | "#" | "!" | ...).

  21. string::= double_quoted_string |single_quoted_string|reverse_quoted_string,

  22. escaped_symbol::=backslash char,

  23. double_quoted_string::= double_quote #( value_of_variable | value_of_argument | #(char~double_quote) | escaped_symbol) double_quote,
  24. reverse_quoted_string::=backquote pipeline backquote,
  25. single_quoted_string::=quote #(char~quote | escaped_symbol) quote.

End