[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci Dept] / [R J Botting] / [Samples] / shell.syntax
[Index] [Contents] [Source Text] [About] [Notation] [Copyright] [Comment/Contact] [Search ]
Tue Sep 18 15:26:55 PDT 2007

Contents


    UNIX Shells

      Lexemes used in UNIX Shells

      [ /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 #digit,
    19. value_of_argument::="$"digit #digit.

      There are several special variables/values:

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

    21. For s:identifier|number, value(s)::= "$" s.

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

    23. escaped_symbol::=backslash char,

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

    . . . . . . . . . ( end of section UNIX Shells) <<Contents | End>>

End