Subject : UNIX C-SHELL PROGRAMMING ±â¹ý(3) 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: 19. ¸í·É¾îÀÇ ´ëü 1) ¸í·É¾îÀÇ º¯¼ö ÇÒ´ç korn shellÀÇ °æ¿ì c-shellÀÇ °æ¿ì typeset <º¯¼ö¸í> = $(<¸í·É¾î>) set <º¯¼ö¸í> = <'¸í·É¾î'> 2) ¸í·É¾îÀÇ ´ëü ¸í·É¾î¸¦ º¯¼ö¿¡ ÇÒ´çÇÏ¿© ¸í·É¾îÀÇ Àμö·Î »ç¿ëÇÏ´Â °ÍÀÌ ¾Æ´Ï¶ó ¸í·É¾îÀÇ Àμö·Î ¸í·É¾î¸¦ »ç ¿ëÇÏ¿© ´ëüÇÏ¿© Çؼ®µÈÈÄ ¼öÇàÇÑ´Ù. 20. ¸í·É¾î Áý´ÜÈ¿¡ À¯¿ëÇÑ ¹®ÀÚ¹× ¸í·É ¹®ÀÚ¹× ¸í·É °á°ú ¹× ¼³¸í ECHO <¸í·É¿> Ãâ·Â¿¡ <¹®ÀÚ¿>ÀÌ Ç¥½Ã ; ¸í·É¾î¿Í ¸í·É¾î ±¸ºÐ \ ¸í·ÉÀÌ ÇÑ LINEÀ» ÃÊ°úÇÒ°æ¿ì ¿¬°á ( ) ¸í·É¾î GROUPÀ» Ç¥½Ã " " ()¿Í °°ÀÌ C-SHELL¿¡ ¸í·É¾î GROUPÀ» Ç¥½ÃÇÏ¿© Çؼ®Çϵµ·ÏÇÔ 21. BACKGROUND »óÅ¿¡¼ PROCESS¼öÇà 1) BACKGROUND »óÅ¿¡¼ ÀԷµǴ º¸ÅëÀÇ ¸í·É¾î¿Í °ü°è ¾øÀÌ PROCESS¸¦ ¼öÇà ½ÃÅ°´Â °÷À» ¸»ÇÑ´Ù. <¼öÇà½Ãų ¸í·É¾î> & * ¼öÇàÈÄ "[ÀÛ¾÷¹øÈ£] PROCESS¹øÈ£ " ÀÇÇü½ÄÀ¸·Î MESSAGE°¡Ãâ·ÂµÈ´Ù. 2) login shellÀÇ Á¾·á init process ´Â systemÀ» ½ÃÀÛÇßÀ»¶§ ¼öÇàÀÌ ½ÃÀ۵Ǹç system°ü¸®ÀÚ³ª consol¿¡ ÀÇÇØ °ü¸®µÇ °í Ã¥ÀÓÀ» °®°ÔµÈ´Ù. »ç¿ëÀÚ°¡ logoutÇϸé login shell°ú ÇÔ²² background¿¡¼ ¼öÇàµÇ´Â process°¡ Á¾·áµÇ´Â°ÍÀÌ ¾Æ ´Ï¶ó background processÀÇ ºÎ¸ð process¸¦ login shell¿¡¼ init process·Î ¿Å°Ü ÇÒ´çµÈ´Ù. 3) backgroundÀÛ¾÷ÀÇ Ç¥ÁØ ÀÔ·Â .login file¿¡¼ set notify·Î ¼³Á¤Çϸé backgound ÀÛ¾÷Áß¿¡ system¿¡¼ ´ëȽÄÀ¸·Î ¿ä±¸µÇ´Â ÀÔ·ÂÀ» ÇÒ ¼ö ÀְԵȴÙ. Áï, backgroundÀÛ¾÷Áß Ç¥ÁØ ÀÔ·Â (key board)·Î ºÎÅÍ ÀÔ·ÂÀ» ÇØ¾ß ÇÒ °æ¿ì system¿¡¼ message¸¦ Ãâ·ÂÇÏ¿© ÀÔ·ÂÀ» ¿ä±¸Çϸç ÀÔ·ÂÀÌ µÇ¸é °è¼Ó ¼öÇàµÈ´Ù. fg <ÀÛ¾÷ ¹øÈ£> 4) sleep¸í·É¾î ÁöÁ¤ÇÑ ½Ã°£µ¿¾È ¸í·É¾îÀÇ ¼öÇàÀ» ÀϽà Á¤Áö ½ÃÅ°´Â ¸í·É¾î sleep <½Ã°£ : ¼ýÀÚ>; <¼öÇà ¸í·É¾î> & 22. »ç¿ëÀÚ processÀÇ ½ÇÇà ¼øÀ§ÀÇ Á¶Á¤ º¸ÅëÀÇ ¸í·Éº¸´Ù ³·Àº ½ÇÇà ¼øÀ§·Î ¸í·ÉÀ» ¼öÇà ½ÃÅ°¸é ±ä ó¸® ½Ã°£ÈÄ¿¡ ¿Ï·áµÈ´Ù. º¸ÅëÀÇ process´Â 0ÀÇ ½ÇÇà ¼øÀ§¸¦ °®À¸¸ç, -20~20±îÁöÀÇ ¹üÀ§¿¡¼ ¼³Á¤ ÇÒ ¼ö ÀÖ´Ù. nice <½ÇÇà¼øÀ§> <¼öÇà¸í·É¾î> & ´ÙÀ½Àº À¯¿ëÇÏ°Ô »ç¿ëµÇ´Â ½ÇÇà ¼øÀ§ÀÌ´Ù. ½ÇÇà ¼øÀ§ ¼³ ¸í +19 process°¡ ¸Å¿ì ´À¸®°Ô ¼öÇàµÈ´Ù. +10 nice¸í·É¾îÀÇ ½ÇÇà ¼øÀ§¸¦ ÁöÁ¤ÇÏÁö ¾ÊÀ»¶§ ±âº» ½ÇÇà ¼øÀ§ 0 º¸Åë ÀÛ¾÷ÀÇ ½ÇÇà ¼øÀ§ -1 ~ -20 system°ü¸®ÀÚ¸¸ ¼³Á¤ ÇÒ¼öÀÖ´Â ½ÇÇà¼ø¼·Î process¸¦ ºü¸£°Ô ¼öÇà½ÃŲ´Ù. 23. ¼öÇàÁßÀÎ processÀÇ Á¤Áö¿Í Àç ¼öÇà jobs¸í·ÉÀº ÀÛ¾÷ ¹øÈ£¿¡ ÀÇÇؼ ÀÛ¾÷ÀÇ list¸¦ Ãâ·Â ½ÃŲ´Ù. ÀÛ¾÷ Á¦¾î ¸í·É¾î ¸í·É¾î ¼³ ¸í <¸í·É¾î> & background¿¡¼ ¸í·É¾î³ª ÀÛ¾÷À» ¼öÇà jobs Á¤Áö»óųª ¼öÇàÁßÀÎ ÀÛ¾÷ ¹øÈ£¸¦ È°µ¿ »óÅÂÀÇ ÀÛ¾÷ list Ãâ·Â stop<ÀÛ¾÷¹øÈ£> ÁöÁ¤ÇÑ backgroundÀÛ¾÷ÀÇ Á¤Áö Ctrl+Z ÇöÀç ¼öÇàÁßÀÎ foregroundÀÛ¾÷ÀÇ Á¤Áö Kill PID PID¹øÈ£¿¡ ÀÇÇØ ÀÛ¾÷À» TERM/sjg·Î À̸§Áö¾îÁø ¹øÈ£¸¦ º¸³»¸é¼ Á¤Áö Kill-l ÀÛ¾÷ Á¤Áö ½ÅÈ£ÀÇ list bg <ÀÛ¾÷¹øÈ£> backgroundÀÛ¾÷À» °è¼Ó ¼öÇà fg <ÀÛ¾÷¹øÈ£> foreground ÀÛ¾÷À» °è¼Ó ¼öÇà 24. C-SHELL¸¦ ÀÌ¿ëÇÑ PROGRAM ¿¹ (cadds file backup¿ë) # # default backsrc script # set io = "tar: read error: I/O error" while(1) set d = `date` echo ' ' echo ' ' echo " DATE : "$d[6]. $d[2]. $d[3]. echo " TIME : "$d[4] echo '' echo ' ******************************************************' echo ' CREATE TAPE ARCHIVES, AND ADD OR EXTRACT FILES' echo ' ******************************************************' echo '' echo ' ************************************************' echo ' * 1. file list for m.t *' echo ' * 2. back up (work station ===> m.t) *' echo ' * 3. restore (m.t ===> work station) *' echo ' * 4. exit *' echo ' ************************************************' echo '' echo -n ' WHAT DO YOU WANT TO EXECUTE ? ---- NO. : ' set test = $< echo '' if ($test) then if($test == 1) then mt -f /dev/rst0 rewind while(1) echo ' ******************************************************' echo ' * Display table of contents of the archive *' echo ' ******************************************************' echo '' tar -tvf /dev/nrst0 echo -n ' Continue ("y"/"n") ....................: ' set cont = $< if($cont == n) break end else if ($test == 2) then while(1) echo '' echo ' *******************************************' echo ' * BACKUP MODE *' echo ' *******************************************' echo '' echo -n ' INPUT (file & directory) ............. : ' set fldir = $< tar -cvf /dev/nrst0 $fldir echo -n ' Continue ("y"/"n") ....................: ' set cont = $< if($cont == n) break end else if ($test == 3) then mt -f /dev/rst0 rewind while(1) echo '' echo ' *******************************************' echo ' * RESTORE MODE *' echo ' *******************************************' echo '' echo -n ' INPUT (skip over the end of file).... : ' set skip = $< mt -f /dev/nrst0 fsf $skip echo -n ' INPUT (file & directory) ............. : ' set fldir = $< tar -xvf /dev/nrst0 $fldir echo -n ' Continue ("y"/"n") ....................: ' set cont = $< if($cont == n) break end else if ($test == 4) then break endif end mt -f /dev/rst0 rewind echo ' ***** END OF BACKUP/RESTORE C-SHEEL ***** ' 26.ÀϹÝÀûÀÎ UNIX ¸í·Éµé (1) FILE°ú DIRECTORY °ü¸® ¸í·É .cat .cd,cddir .chmod .cp .file .find .head .ln .ls .mkdir .more .mv .rm .rmdir .tail .tee (2) TEXT 󸮸í·É .awk ; Aho,Weinberger,Kernighan ;text¿¡¼ ÆмÏÀ» ã°í ¾î¶²µ¿ÀÛÀ» ÇàÇÑ´Ù. .diff .ex .grep .lpr .nroff .pr .sed .sort .spell .split .tr .vi .wc (3) SYSTEM»óÅÂÀÇ ¸í·É .date .du .env : ÇöÀçÀÇ È¯°æº¯¼ö¸¦ display .id .kill .mail .news .ps .pwd .stty .tset .tty .who .write (4) SOFTWARE °³¹ß¸í·É .ar : ÀúÀå¹× ¶óÀ̺귯¸® °ü¸® .cb : C beautifier .cc : .cmp .nm .od .size Revision History ÀÛ¼ºÀÏÀÚ : 96.06.14 ÀÛ¼ºÀÚ : ±èµµ°æ ¼öÁ¤ÀÏÀÚ : ¼öÁ¤ÀÚ