Subject : UNIX C-SHELL PROGRAMMING ±â¹ý(1) Description : CONTENTS: 1. C-SHEELÀ̶õ 2. UNIX SHEELÀÇ ÁÖ¿ä Ư¼º 3. C-SHEELÀÇ ¿ëµµ 4. SHELLÀÇ Á¾·ù 5. SHELL ¸í·É¾î¿Í ¸í·É¾î FILE 6. SHELL SCRIPTÀÛ¼º½Ã ÁÖÀÇ »çÇ× 7. SHELL SCRIPTÀÇ ¼öÇà 8. shell script º¯¼ö 9. temporary fileÀÇ »ç¿ë 10. shell script Á¦¾î¹® 11. ¹Ýº¹ Á¦¾î¹®ÀÇ Á¾·ù 12. Àμö list ó¸® 13. ȯ°æ º¯¼öÀÇ »ç¿ë(º¯¼ö¸íÀº ´ë¹®ÀÚ) 14. ±âÁ¤ º¯¼öÀÇ »ç¿ë (setÀ¸·Î ³»¿ë °Ë»ö) 15. shell º¯¼öÀÇ Æ¯¼º 16. ¹®ÀÚ single(') ¿Í double(") ¿Í backword apostroples(') »çÀÌÀÇ Â÷ÀÌÁ¡ 17. shell º¯¼ö¸¦ »ç¿ëÇÑ »ê¼ú ¿¬»ê 18. shell scriptÀÇ debugging 19. ¸í·É¾îÀÇ ´ëü 20. ¸í·É¾î Áý´ÜÈ¿¡ À¯¿ëÇÑ ¹®ÀÚ¹× ¸í·É 21. BACKGROUND »óÅ¿¡¼ PROCESS¼öÇà 22. »ç¿ëÀÚ processÀÇ ½ÇÇà ¼øÀ§ÀÇ Á¶Á¤ 23. ¼öÇàÁßÀÎ processÀÇ Á¤Áö¿Í Àç ¼öÇà 24. C-SHELL¸¦ ÀÌ¿ëÇÑ PROGRAM ¿¹ 25.ÀϹÝÀûÀÎ UNIX ¸í·Éµé DESCRIPTION: 1. C-SHEELÀ̶õ . »ç¿ëÀÚ interfaceÀÌ´Ù. . ¾î¶² ƯÁ¤ÇÑ »óÅ°¡¾ø´Ù. . C-PROGRAM¾ð¾î¿Í À¯»çÇÑ ±¸¹®À» °®´Â °·ÂÇÑ ¸í·É¾ð¾î¸¦ Á¦°øÇÑ´Ù. . UNIXÀÇ »ç¿ëÀ» ÈÙ¾À ½±°Ô ÇØÁØ´Ù. . utility, ƯÁ¤ »ç¿ëÀÚ interface¿Í process FILE, ½ÉÁö¾î´Â ¹ü¿ë program ¸¶Àúµµ ½Å¼ÓÇÏ°Ô °³¹ßÇÒ ¼ö ÀÖµµ·Ï ÇÑ´Ù. 2. UNIX SHEELÀÇ ÁÖ¿ä Ư¼º (1) .cshrc .login .logout°°Àº Ư¼öFILEÀ» »ç¿ëÇÏ¿© ÀÚ½ÅÀÇ sessionÀ» ÃëÇâ¿¡ ¸Âµµ·Ï ¼öÁ¤ÇÒ¼ö ÀÖ´Ù. (2) HISTORY±â´ÉÀ» ¾²¸é ¸í·ÉÀ» ´Ù½Ã ½ÇÇàÇÒ ¼ö ÀÖÀ¸¸ç ALIAS¸¦ ¾²¸é ¿¬¼ÓµÈ ¸í·ÉÀ» ´Ù¸¥ À̸§ À¸·Î »ç¿ëÇÒ¼öÀÖ´Ù. (3) SHEELº¯¼ö¸¦ ¾²¸é ¿¬¼ÓµÇ´Â ¸í·É¿¡¼ ±ä¹®ÀÚ¸¦ Àç»ç¿ë ÇÒ ¼ö ÀÖµµ·Ï ÀúÀåÇÒ ¼öÀÖ´Ù. ÀÔÃâ·Â ¹æÇâÀüȯ, ¸í·ÉGROUP, ¸í·É ġȯ µîÀº ¸í·ÉÀ» ±¸¼ºÇϱâ À§ÇÑ C-SHEELÀÇ ±âº»¿ä¼Ò´Ù. (4) UNIXÀÇFILE SYSTEMÀº °èÃþÀû ±¸Á¶¸¦ °¡Áö°íÀÖ´Ù. FILEÀ» ÁöÁ¤ÇÏ´Â °ÍÀº ÇöÀç DIRECTORY³ª ROOT DIRECTIRY·Î ½ÃÀÛÇÏ´Â °æ·ÎÀ̸§À» »ç¿ëÇÑ´Ù. (5) C-SHEELÀº ÇÁ·Î±×·¥ ¾ð¾îÀÌ´Ù. »õ·Î¿î µµ±¸¸¦ âÁ¶ÇØ ³»´Â°ÍÀº C-SHEEL SCRIPT,C-SHEEL ¸í·É, PROGRAM±¸Á¶, ERROR°Ë»ç, ÀÔÃâ·Â ¸í½ÃµîÀ» Æ÷ÇÔÇÏ´Â TEXT FILEÀÇ ÀÛ¼ºÀ» ÅëÇؼ ÀÌ·ç¾îÁø´Ù. 3. C-SHEELÀÇ ¿ëµµ ´ÙÀ½ 3°¡Áö ¹æ¹ýÀ¸·Î »ç¿ëÇÒ ¼öÀÖ´Ù. (1) ´ëÈÀûÀ¸·Î UNIX¸í·ÉÀ» ½Ç¿ëÇϱâ À§ÇØ (2) °³ÀÎÈ¿¡¼ ÀÛ¾÷ ȯ°æÀ» Á¤ÀÇÇϱâÀ§ÇØ (3) PROGRAM¿¡¼ C-SHEEL PROGRAM°°Àº »õ·Î¿î µµ±¸¸¦ »ý¼ºÇϱâÀ§ÇØ 4. SHELLÀÇ Á¾·ù (1) C-SHELL(csh) : C PROGRAM¾ð¾î·Î ºÎÅÍ ±×±¸Á¶¿Í À̸§ÀÌ À¯·¡µÊ (2) UNIX Ç¥ÁØ BOURNE SHEEL (sh) (3) UNIX V BOURNE SHELL (sh5) (4) KORN SHELL (ksh) : BOURNE SHELL·Î ºÎÅÍ À¯·¡µÈ ÃÖ±ÙÀÇ SHELL 5. SHELL ¸í·É¾î¿Í ¸í·É¾î FILE (1) PROFILE°ú .profile ¸í·É FILE ¸ðµç »ç¿ëÀÚ¿¡°Ô Àû¿ëµÇ´Â SHELL¸í·É FILEÀº /etc/profileÀε¥ »ç¿ëÀÚ°¡ loginÇÏ¿© »ç¿ëÀÚÀÇ directoryÀÇ ¸í·É fileÀ» ¼öÇàÇϱâ Àü¿¡ ½ÇÇàÇϵµ·Ï system °ü¸®ÀÚ°¡ ±âº»ÀûÀ¸·Î ¼³Á¤ÇÑ ¸í·É fileÀÌ´Ù.°¢ »ç¿ëÀÚ´Â etc/profileÀ» ¼öÇàÇÑÈÄ ÀÚ½ÅÀÌ ¼³Á¤ÇÑ ¸í·É fileÀ» loginÇÑÈÄ ¹Ù·Î ½ÇÇà ½Ãų¼ö Àִµ¥ .profile¿¡ ¸í·ÉÀ» ¼³Á¤ÇÏ¸é µÈ´Ù. (¿¹) .profile FILE tty -s if test $? = 0 then stty dec crt fi PATH=.:$HOME/bin:/usr/ucb:/bin:/usr/bin:/usr/local:/usr/new:/usr/hosts MAIL=/usr/spool/mail/$USER tset -n -I export TERM MAIL PATH biff n (2) .cshrc ¸í·É¾î file (c-shell¸¸ »ç¿ë) ´Ù¾çÇÑ °æ·ÎÀÇ º¯°æÀ̳ª Àüü¿¡ ¿µÇâÀ» ¹ÌÄ¡´Â alias°ªµîÀÇ ¼³Á¤À» º¯°æÇÏ·Á´Â ¸í·ÉÀ» ÁöÁ¤ÇÏ´Â µ¥ »ç¿ëÇÏ´Â fileÀÌ´Ù. .cshrc fileÀº HOME DIRECTORY¿¡ Á¸ÀçÇÏ¿© C-SHELL¿¡ ÀÇÇØ Çؼ®µÈ´Ù. ÀÌ FILEÀº SHELL SCRIPT¸¦ È¿À²ÀûÀ¸·Î »ç¿ë ÇÒ ¼ö ÀÖµµ·Ï º¯¼ö ÇÒ´ç, ERROR CODE¿Í °°Àº Áøº¸µÈ ±â´ÉÀ» À§ÇØ ÀÌ¿ëµÈ´Ù. (¿¹) .cshrc FILE if ($?prompt) then set prompt = "csh> " set notify set history = 50 set term = vt100 alias h history alias gc setenv GKS3Dconid basic002:0.0 alias ung unsetenv GKS3Dconid alias unws unsetenv GKS3Dwstype alias gpr setenv GKS3Dconid /dev/tty01 alias gp setenv GKS3Dwstype %x10500033 alias gl setenv GKS3Dwstype %x00500033 alias isl4 setenv GKS3Dwstype %x0070003d alias l "pwd;ls -F" alias pd pushd alias pop popd alias help apropos alias vt52 "set term = vt52" alias ti745 "set term = ti745 ; stty -tabs" alias ti785 "set term = ti745 ; stty -tabs" alias vt100 "set term = vt100" alias _dry cd /usr/skb/dry_source alias _opti cd /usr/skb/dry_source/opti alias _daed cd /usr/skb/dry_source/contact alias _marpol cd $HOME/sd9112/marpol alias _source cd $HOME/../source/sikob_source alias dryrun /usr/skb/dry_source/rev3/dryrun alias gendat /usr/skb/dry_source/rev3/gendat alias profile /usr/skb/dry_source/rev1/profile alias prelikon cd /usr/sbdd1.users/sikob/source/prelikon alias pkdata cd /usr/sbdd1.users/pkdata alias hpgl "echo '||e5' > /dev/tty01;setenv GKS3Dconid /dev/tty01" alias lo 'echo -n "From> ";set w = $<; find $w -name \!* -print;unset w' # alias cd 'cd \!*;set cwdd="$cwd:t";if($cwdd == '' ) set cwdd='/';set prompt="`hostname` SIKOB[$cwdd]> "' alias cd 'cd \!*;set prompt="SIKOB [`dirs`]>"' endif (3) .login ¸í·É¾î file (c-shell¸¸ »ç¿ë) ¸¸¾à login shellÀÌ c-shellÀ̸é HOME DIRECTORY ³»¿¡ Á¸ÀçÇÏ´Â .login FILEÀ» ÀÐÀºÈÄ ±×³»¿ëÀ» ¼ø¼´ë·Î ½ÇÇà½ÃŲ´Ù. .login FILE¿¡´Â ¸¹Àº ¸í·ÉÀÌ ÀÖÀ¸³ª ƯÈ÷, SHELL ÀÚü¿¡ ´ëÇÑ ¼³Á¤ ¸í·É SET°¡ ¸¹ÀÌ ÀÖ´Ù. (¿¹) .login FILE stty dec new cr0 tset -I -Q umask 022 setenv MAIL /usr/spool/mail/$USER set mail=$MAIL set path=(. $HOME/bin /usr/ucb /bin /usr/bin /usr/local /usr/new /usr/hosts /usr/users/sikob/bin/skcpl) set prompt="SIKOB > " setenv EXINIT 'set redraw wm=8' setenv DECFORT_FFRLIB "T" biff n date (4) .logout ¸í·É¾î file (c-shell¸¸ »ç¿ë) logout¸í·ÉÀ» ¼öÇà ½ÃÅ°¸é file logout¿¡ ÀúÀåµÈ ¸í·ÉÀ» ½ÇÇà ½ÃŲ´Ù. (¿¹) .logout FILE # # default cadds user logout script # # 24-Jun-86 HPS; 'oplog off' is commented out # 25-mar-86 jaf; moved # 11-mar-86 aws; created ###################################################################### # #oplog off #clear cal 6. SHELL SCRIPTÀÛ¼º½Ã ÁÖÀÇ »çÇ× (1) ù¹ø° LINE ù COLUMEÀº #! ·Î½ÃÀÛÇÏ¸ç ±×³»¿ëÀ» Àд »ç¶÷ÀÌ ¾Ë±â ½±µµ·Ï SHELL SCRIPT¸¦ ¼öÇàÇÏ´Â SHELLÀÇ °æ·Î¸íÀ» Àû´Â´Ù. (2) SHELL SCRIPT´Â º¸Åë ÀÛ¼ºÀÚ°¡ ½±°Ô °£°úÇعö´Â ÁÖ¼®¿¡ ´ëÇØ °Á¶ÇÏ¿© ÀÛ¼ºÇÑ´Ù. (3) ÁÖ¼®Àº #À¸·Î ½ÃÀÛÇϸç SHELL¿¡ ÀÇÇØ ¸í·É¾î·Î Çؼ®µÇÁö ¾Ê´Â´Ù. ÇÏÁö¸¸ ¸¸ÀÏÀÇ °æ¿ì ¸í·É¾î·Î Çؼ®µÇ°ÍÀ» ¹æÁö Çϱâ À§ÇØ # ´ÙÀ½¿¡ QUOTATION MARK·Î ¹®ÀÚÀ» ¿°í ´Ý´Â´Ù. (4) ¸í·É¾î¸¦ ÀûÀºÈÄ µ¿ÀÏ LINE¿¡ #À¸·Î ½ÃÀÛÇÏ´Â ÁÖ¼®À» IN LINE COMEND¶ó°í ÇÏ¸ç ¸í·É¾îÀÇ ¸¶Áö¸·¿¡ ;À» »ç¿ëÇÏ¿© ¸í·É¾î¿Í IN-LINE COMEND¿Í ºÐ¸® ÇÑ´Ù. (5) ECHO ¸í·ÉÀº ECHO ¸í·É ´ÙÀ½ÀÇ ¸í·É°ú ÇÔ²² Ãâ·ÂÇϴµ¥ À¯¿ëÇÏ°Ô »ç¿ëµÈ´Ù. 7. SHELL SCRIPTÀÇ ¼öÇà ¨ç SUB-SHELLÀ» ¼öÇà ½ÃŲ´Ù. ¨è »ç¿ëÀÚÀÇ ÇöÀç SHELL³»¿¡¼ SCRIPT¸¦ ¼öÇà ½ÃŲ´Ù. ¨é SCRIPT¸¦ ¼öÇà °¡´ÉÇÏ°Ô ¸¸µç´Ù. (1) SUB-SHELLÀÇ ¼öÇà BOURNE SHELLÀÇ °æ¿ì : shC-SHELL ÀÇ °æ¿ì : csh (2) »ç¿ëÀÚÀÇ ÇöÀç shell³»¿¡¼ script ¼öÇà source 8. shell script º¯¼ö (1) º¯¼ö¸í ºÎ¿©½Ã ÁÖÀÇ »çÇ× ¨ç º¯¼öÀÇ À̸§Àº ¹®ÀÚ·Î ½ÃÀÛÇÑ´Ù. ¨è º¯¼ö´Â ¹®ÀÚ, ¼ýÀÚ, ¹ØÁÙ·Î ±¸¼ºÇÑ´Ù. ¨é ±æÀÌ´Â 20ÀÚ±îÁö Á¦ÇÑÇÑ´Ù. (2) º¯¼ö¿¡ °ªÇÒ´ç/ÇØÁ¦ º¯¼ö¿¡ °ªÀ» ÇÒ´çÇÏ´Â ¹®ÀÚ = ¸¦ »ç¿ëÇÏ°í ¾ÕµÚ¿¡ °ø¹éÀÌ ¾ø¾î¾ßÇÑ´Ù. ¼³Á¤ set <º¯¼ö¸í> = <°ª> * °ªÀÌ ¹®ÀÚ¿ÀÎ °æ¿ì " " double quotation »ç¿ë ÇØÁ¦ $ unset <º¯¼ö¸í> (3) º¯¼ö°ª Ãâ·Â echo $ <º¯¼ö¸í> echo " " echo <´Ü¾î> (4) read¹®ÀåÀ» ÀÌ¿ëÇÑ °ªÇÒ´ç Ç¥ÁØ ÀÔ·Â (key board)·Î ÀÔ·ÂÀ» ¹Þ¾Æ º¯¼ö¿¡ °ªÀ» Á÷Á¢ ÇÒ´ç read <º¯¼ö¸í> = $< Revision History ÀÛ¼ºÀÏÀÚ : 96.06.14 ÀÛ¼ºÀÚ : ±èµµ°æ ¼öÁ¤ÀÏÀÚ : ¼öÁ¤ÀÚ