Computer Science 175a:
Telling Bourne Shell, AWK, and C Apart

[Home] [Outline] [Calendar] [Schedule] [Topics] [Assignments] [Exams] Telling Languages Apart

          |          sh          |         awk          |          C           |
----------+----------------------+----------------------+----------------------+
Program   |                      |                      |                      |
  instance| executable script    | executable script    | extension of .c      |
          |                      |                      |                      |
 structure| #! /bin/sh           | #!/bin/awk -f        | name( arglist )      |
          | UNIX commands        | pattern {expression} | {                    |
          |                      |        or            |    statement(s)      |
          |                      | awk 'pat{expr}'      | }                    |
          |                      |                      |                      |
  comments| everything after #   | # at begin of line   | /* */                |
----------+----------------------+----------------------+----------------------+
Variable  |                      |                      |                      |
     names|[A-Za-z_][A-Za-z_0-9]*|[A-Za-z_][A-Za-z_0-9]*|[A-Za-z_][A-Za-z_0-9]*|
          |                      |Fields: $[0-9][0-9]*  |                      |
          |                      |                      |                      |
   declare| first use            | first use            | before use           |
          |                      |                      |                      |
     types| string               | string               | int, float, etc.     |
          |                      | but can be numbers   |                      |
          |                      |                      |                      |
   initial| set to ""            | set to "" or 0       | undefined!!!!!!!!!!  |
          |                      |                      |                      |
 operators| VAR=stuff            | arith: + - * / % =   | arith: + - * / % =   |
          | UNIX I/O Redirection | rel: == != < <= > >= | = += -= *= /= ++ --  |
          |                      |      && ||           | rel: == != < <= > >= |
          |                      | concat: space        |      && ||           |
          |                      |                      |                      |
     value| preceed name with $  | just use them        | just use them        |
 retrieval| to differentiate     |                      |                      |
          | from UNIX commands   |                      |                      |
          |                      |                      |                      |
     scope| local by default     | global by default    | local inside funcs   |
          | export to make global|                      | global outside funcs |
          | parent cannot see    |                      |                      |
          |     childs env.      |                      |                      |
----------+----------------------+----------------------+----------------------+
Control   |                      |                      |                      |
        if| if cmd               | if ( expr ) { stmt } | if ( expr ) stmt     |
          | then cmd             |                      |                      |
          | [elif cmd]           |                      |                      |
          | [then cmd]           |                      |                      |
          | [else cmd]           |                      |                      |
          | fi                   |                      |                      |
          |                      |                      |                      |
       for| for var in list      | for (e;e;e) { stmt } | for (e;e;e) stmt     |
          | do cmd...            |                      |                      |
          | done                 |                      |                      |
          |                      |                      |                      |
     while| while cmd            | while (e) { stmt }   | while (e) stmt       |
          | do cmd...            |                      |                      |
          | done                 |                      |                      |
----------+----------------------+----------------------+----------------------+