1993.1.3

SUBJECT: C shell, Bourne shell¿¡¼­ÀÇ Å×½ºÆ® ¹æ½Ä ºñ±³

MEANING OF THIS MEMO
shell program½Ã ÈçÈ÷ Á¶°Ç Å×½ºÆ®·Î »ç¿ëÇÏ´Â flag¿Í operator¿¡ ´ëÇØ
C shell, Bourne shell ¾ç ÂÊÀÇ °ÍÀ» ºñ±³ÇØ º¸¾Ò´Ù.

CONTENTS:
0. "test" command¿¡ ´ëÇÏ¿©
1. C shell¿¡¼­ÀÇ Å×½ºÆ® ¹æ½Ä
2. Bourne shell¿¡¼­ÀÇ Å×½ºÆ® ¹æ½Ä
3. C shell, Bourne shellÀÇ Å×½ºÆ® ºñ±³
4. Âü°í - OperatorÀÇ ºñ±³

DESCRIPTION:

0. "test" command¿¡ ´ëÇÏ¿©

   * "test" command(ÀÌÇÏ "test"·Î »ý·«ÇÔ)´Â ¿ø·¡ user command·Î Á¸ÀçÇÏ´Â °ÍÀÌ´Ù.
     syntax¸¦ º¸¸é,
     +-----------------------------+
     |    % test       | 
     +-----------------------------+
     À» testÇÏ¿© ±× °ªÀÌ ÂüÀ̸é 0 À» returnÇÏ°í
     °ÅÁþÀ̸é 1 À» returnÇÑ´Ù.

   * Àº logicalÇÏ°Ô Å©°Ô µÎ °¡Áö ¿ä¼Ò·Î Ç¥Çö µÈ´Ù.
     ¨ç Primitives  
           "-b ", "-c "ÀÇ syntax¸¦ °¡Áø´Ù.
           ¿¡ ´ëÇØ -ÀÇ Àǹ̸¦ testÇ϶ó´Â °ÍÀÌ´Ù.
           ¾Æ·¡ Ç¥¿¡¼­ ±¸Ã¼ÀûÀ¸·Î »ìÆ캼 °ÍÀÌ´Ù.
     ¨è Operators 
           ¾ÕÀÇ PrimitiveµéÀ» ¿¬°áÇϴµ¥ »ç¿ëµÈ´Ù.
           - Unary Operator  :   ! (logical NEGATION)
           - Binary Operator :  -a (logical AND)
                                -o (logical OR)
           - ( )             :  groupingÀ» À§ÇÑ °ÍÀ¸·Î
                                °ýÈ£ ¾È¿¡´Â ÀÌ µé¾î °£´Ù.

1. C shell¿¡¼­ÀÇ Å×½ºÆ® ¹æ½Ä
   * "test"ÀÇ man page¸¦ º¸¸é ¾Ë ¼ö ÀÖµíÀÌ
     »ó´ç ºÎºÐÀÇ PrimitiveµéÀÌ cshÀÇ °æ¿ì built-in µÇ¾î ÀÖ´Ù.
   * µû¶ó¼­ C shell programming½Ã¿¡´Â built-inµÈ comand·Î Å×½ºÆ®Åä·Ï ÇÏ°í
     built-in command¿¡ ¾ø´Â °ÍÀ» Å×½ºÆ®ÇÏ·Á´Â °æ¿ì
     "test"ÀÇ PrimitiveµéÀ» »ç¿ëÇÏ¸é µÉ °Í.
     Å×½ºÆ®¿Í °ü·ÃÇÑ C shellÀÇ built-in commandµéÀº ¾Æ·¡ Ç¥ ÂüÁ¶.

2. Bourne shell¿¡¼­ÀÇ Å×½ºÆ® ¹æ½Ä
   * ÀÌ "test"´Â C shell º¸´Ù´Â Bourne shell¿¡¼­ ´õ¿í ÀÚÁÖ »ç¿ëµÇ´Âµ¥,
     ÀÌ´Â Bourne shell¿¡ Å×½ºÆ®¸¦ À§ÇÑ built-in command°¡ ºó¾àÇϱ⠶§¹®ÀÌ´Ù.
   * Bourne shell¿¡¼­ "test"¸¦ »ç¿ëÇÒ ¶§ "test" syntax¸¦ µû¸£±â º¸´Ù´Â
     "test"¿Í °°Àº Àǹ̷Π»ç¿ëµÇ´Â "[" (¹°·Ð "]"µµ ÇÔ²²)¸¦ »ç¿ëÇÑ´Ù. 
     ¿©·¯ Bourne shell scriptµé¿¡¼­ if¿Í ÇÔ²² ³ª¿À´Â "["¸¦ ÀÚÁÖ º¸´Âµ¥, ÀÌ´Â
     Bourne shell 'Á¶°Ç¹® ifÀÇ syntax'°¡ ¾Æ´Ï¶ó "test"ÀÇ ´ë¿ëÀ̶ó´Â Á¡À» ÁÖÁöÇϽþÐ. 
   * C shell¿¡¼­ "["¸¦ »ç¿ëÇÏ¿© Å×½ºÆ®¸¦ ¼öÇàÇÏ·Á¸é,
     "["°ú "]"´Â backslash·Î escapeµÇ¾î¾ß ÇÑ´Ù.
     example)  if { \[ -r filename \] } then
     


3. C shell, Bourne shellÀÇ Å×½ºÆ® ºñ±³
                                                   +------------+------------+
   +-------+---------------------------------------| C shell    |  "test"    |
   | ´ë »ó |      Å×  ½º  Æ®      ÀÇ    ¹Ì         | (built-in) |  command   |
   +=======+=======================================+============+============+
   |       |                                       |          Flag           |
   |       |                                       +=========================+
   |       |  directory                            |            -d           |
   |       |  file                                 |            -f           |
   |       |  file or directory exists             |    -e                   |
   |       |  owned by the executing user          |    -o                   |
   |       |  current user can read                |            -r           |
   | File  |  current user can write               |            -w           |
   |       |  current user can execute             |            -x           |
   |       |  exists and size > 0                  |            -s           |
   |       |  size is 0                            |    -z                   |
   |       |  block device                         |                  -b     |        
   |       |  character device                     |                  -c     |        
   |       |  named pipe                           |                  -p     |        
   |       |  set-uid-bit set                      |                  -u     |        
   |       |  set-gid-bit set                      |                  -g     |        
   |       |  stiky bit set                        |                  -k     |        
   |       |  n˼ terminal˂ file descriptor       |                  -t n   |      
   +-------+---------------------------------------+=========================+
   |       |                                       |        Operator         |
   |       |                                       +=========================+
   |       |  NULL                                 |    ==            -z     | ¨Í
   |String |  not NULL                             |    !=            -n     | ¨Î
   |       |  equal                                |    ==            =      |
   |       |  not equal                            |    !=            !=     |
   |       |  match wildcard pattern               |    =~                   | ¨Ï
   |       |  not match wildcard pattern           |    !~                   | ¨Ð
   +-------+---------------------------------------+-------------------------+
   |       |  equal                                |    ==            -eq    |
   |       |  not equal                            |    !=            -ne    |
   |Number |  less than                            |     <            -ne    |
   |       |  greater than                         |     >            -gt    |
   |       |  less than equal                      |    <=            -le    |
   |       |  greater than equal                   |    >=            -ge    |
   +-------+---------------------------------------+-------------------------+
   |       |  logical AND                          |    &&            -a     |
   | ³í ¸® |  logical OR                           |    ||            -o     |
   |       |  logical NEGATION                     |            !            |
   +-------+---------------------------------------+-------------------------+

   * FlagÀÇ °æ¿ì »ç¿ë syntax¸¦ º¸¸é, flag µÚ¿¡ filenameÀ» ÁÖ¸é µÈ´Ù.
   * OperatorÀÇ °æ¿ì »ç¿ë syntax¸¦ º¸¸é,
     unary operator(´ÜÇ× ¿¬»êÀÚ)ÀÎ "!"À» Á¦¿ÜÇÏ°í´Â
     ¸ðµÎ binary operator(ÀÌÇ× ¿¬»êÀÚ)À̹ǷÎ
     operator ¾çÂÊ¿¡ string(or pattern), number¸¦ ÁÖ¸é µÈ´Ù.

   * ¨Í¿¡¼­ »ç¿ë syntax¸¦ º¸¸é,
               C shellÀÇ °æ¿ì : string == ""
               "test"ÀÇ °æ¿ì  : if test -z "$string"
   * ¨Î¿¡¼­ »ç¿ë syntax¸¦ º¸¸é,
               C shellÀÇ °æ¿ì : string != ""
               "test"ÀÇ °æ¿ì  : if test -n "$string"
   * ¨Ï¿¡¼­ »ç¿ë syntax¸¦ º¸¸é, string =~ pattern
   * ¨Ð¿¡¼­ »ç¿ë syntax¸¦ º¸¸é, string !~ pattern



4. Âü°í - OperatorÀÇ ºñ±³
   * C shellÀÇ operatorµéÀº ¸ðµÎ built-inµÈ °ÍµéÀÌ´Ù.
   * Bourne shellÀÇ operatorµé Áß
     °ü°è ¿¬»êÀÚ¿Í ³í¸® ¿¬»êÀÚµéÀº ¾Õ¼­ ¾ð±ÞÇß´ø °Íó·³
     "test"¿¡¼­ ºô·Á´Ù »ç¿ëÇÑ´Ù´Â °ÍÀ» »ó±âÇϽöó.

   +-----------------------------+----------------+----------------+
   |    Operator    Á¾   ·ù      |    C shell     | Bourne shell   |
   +=============+===============+================+================+
   |             |               |       <               -lt       |
   |             | Number only   |       >               -gt       |
   |             |               |       <=              -le       |
   |             |               |       >=              -ge       |
   | Relational  |---------------+----------------+                |
   | Operator    | Number or     |       ==       |      -eq       |
   |             |       String  |       !=       |      -ne       |
   |             |---------------+----------------+----------------+
   |             | String only   |       =~                        |
   |             |               |       !~                        |
   +-----------------------------+---------------------------------+
   |                             |       &&              -a        |
   |    Logical Operator         |       ||              -o        |
   |                             |                !                |
   +-----------------------------+---------------------------------+
   |                             |                +                |
   |                             |                -                |
   |    Arithmetic Operator      |                *                |
   |                             |                /                |
   |                             |                %                |
   +-----------------------------+---------------------------------+
   |                             |       =                         |
   |                             |       +=                        |
   |    Assignment Operator      |       -=                        |
   |                             |       *=                        |
   |                             |       /=                        |
   |                             |       %=                        |
   +---------------------------------------------------------------+





Revision History
Created        on Jan. 3 ,1993