mageoli@hotmail.com http://mageoli.kunsan.ac.kr
½© ÇÁ·Î±×·¡¹Ö 7
- ¸í·É µé -
break : for, whileÀ̳ª until¹®¿¡¼ Á¦¾î Á¶°ÇÀ»
¸¸³ª±â Àü¿¡ ·çÇÁ¸¦ ¹þ¾î³¯ ¶§ »ç¿ëÇÑ´Ù
Å»ÃâÇÒ ¶§ÀÇ ·çÇÁÀÇ ¼ö¸¦ breakÀÇ ¸Å°³ º¯¼ö·Î Áֱ⵵
Çϴµ¥ °ÅÀÇ »ç¿ëÀ» ÇÏÁö ¾Ê´Â´Ù
:(ÄÝ·Ð): ÄÝ·Ð ¸í·ÉÀº Àǹ̾ø´Â (null) ¸í·ÉÀÌ´Ù
°¡²û true¸¦ ´ë½ÅÇØ ³í¸®°ªÀ» °£´ÜÇÏ°Ô ÇϱâÀ§ÇØ
»ç¿ëÇϴµ¥ trueº¸´Ù´Â ´õ ºü¸£°Ô µ¿ÀÛÇÏÁö¸¸
°¡µ¶¼ºÀÌ ¶³¾îÁø´Ù
continue: C¾ð¾î¿¡¼¿Í ºñ½ÁÇÑ ¸í·ÉÀ̸ç for,while, until
·çÇÁÀÇ º¯¼ö¸¦ ´ÙÀ½°ªÀ» °¡Áö°Ô ÇÏ°í ´ÙÀ½¹ø ·çÇÁ¸¦
µ¹°Ô ÇÑ´Ù
.(¸í·É) : . ¸í·ÉÀº ÇöÀçÀÇ ¼ö·¹¿¡¼ ¸í·ÉÀ» ½ÇÇà½ÃÅ°´Â °ÍÀÌ´Ù
Çü½Ä) .shell script
ÀϹÝÀûÀ¸·Î ½ºÅ©¸³Æ®¿¡¼ ½ºÅ©¸³Æ®³ª ¿ÜºÎ ¸í·ÉÀ»
½ÇÇà½Ãų ¶§, »õ·Î¿î ȯ°æÀÌ ¸¸µé¾îÁö°í ¸í·ÉÀº
»õ·Î¿î ȯ°æ¿¡¼ ½ÇÇàµÇ¸ç, ºÎ¸ð ½©·Î µ¹¾Æ°¡´õ¶óµµ
ÀÌÀü ȯ°æÀº ¹«½ÃµÈ´Ù. ±×·¸Áö¸¸ ¿ÜºÎ ¸í·ÉÀÎ source¿Í
. ¸í·ÉÀº ½ºÅ©¸³Æ®¿¡¼ È£ÃâµÈ °°Àº ½©¿¡¼ ¸í·ÉÀ»
½ÇÇà½ÃŲ´Ù
ÀÌ ¸»Àº ÇØ´ç ¸í·É¾î°¡ ±âÁ¸ÀÇ È¯°æ º¯¼ö¸¦ º¯°æÇÒ ¼ö
ÀÖ´Ù´Â ¶æÀÌ´Ù. '.'¸í·ÉÀº ¸í·É¾î°¡ ½ÇÇàµÇ´Â µ¿¾È
ÇöÀç ȯ°æÀ» º¯È½ÃÅ°´Â °ÍÀ» Çã¿ëÇÑ´Ù.
ÀÌ ¸í·ÉÀº ³ªÁß¿¡ ½ÇÇà µÇ´Â ´Ù¸¥ ¸í·ÉÀÇ È¯°æÀ» ¼³Á¤
ÇϱâÀ§ÇÑ 'wrapper'·Î »ç¿ëÇϱ⵵ ÇÑ´Ù. ¿¹¸¦ µé¸é
µ¿½Ã¿¡ ¿©·¯ °¡ÁöÀÇ ´Ù¸¥ ÀÛ¾÷À» ÇÏ°í ÀÖÀ»¶§,
¾Æ¸¶µµ ¿À·¡µÈ ÇÁ·Î±×·¥À» À§ÇØ ±¸¹öÀüÀÇ ÄÄÆÄÀÏ·¯¸¦
»ç¿ëÇÏ·Á¸é ´Ù¸¥ ¸Å°³ º¯¼ö¸¦ »ç¿ëÇØ¾ß ÇÒ ÇÊ¿ä°¡ ÀÖÀ»°Í
ÀÌ´Ù. ½© ½ºÅ©¸³Æ®¿¡¼ ¸í·É¾î´Â C³ª C++¿¡¼ #include
¿Í °°Àº ÀÏÀ»ÇÑ´Ù. ¸» ±×´ë·Î ½ºÅ©¸³Æ®¸¦ Æ÷ÇÔÇϴ°ÍÀº
¾Æ´ÏÁö¸¸ ¹®¸Æ»ó ¸í·ÉÀ» ½ÇÇà½ÃÅ°¸ç, ½ºÅ©¸³Æ® ¾È¿¡ º¯¼ö¿Í
ÇÔ¼öÀÇ Á¤ÀǸ¦ ÅëÇÕÇؼ »ç¿ë ÇÒ¼ö ÀÖ´Ù.
echo : Çö´ëÀûÀÎ ½©¤·¿¡¼ printf ¸í·ÉÀ» »ç¿ëÇϴ°ÍÀÌ ÁÁ´Ù´Â
X/OpenÀÇ ±Ç°í¿¡µµ ºÒ±¸ÇÏ°í °³Çà ¹®ÀÚ¸¦ Æ÷ÇÔÇÑ ¹®ÀåÀ»
°£´ÜÇÏ°Ô Ãâ·ÂÇϴµ¥ ¿©ÀüÈ÷ echo ¸í·ÉÀ» »ç¿ëÇÑ´Ù.
eval : eval ¸í·ÉÀº ÀÎÀÚÀÇ °ªÀ» ±¸Çϴµ¥ »ç¿ëÇÑ´Ù.
½© ³»ºÎ ¸í·ÉÀ¸·Î, ÀϹÝÀûÀÎ ¿ÜºÎ ¸í·ÉÀº ¾Æ´Ï´Ù.
X/Open±Ô¾à¿¡ ÀÖ´Â ¿¹Á¦°¡ °¡Àå ÁÁÀº¿¹°¡ µÉ°ÍÀÌ´Ù.
ex) foo=10
x=foo
y='$' $x
echo $y
ÀÌ°ÍÀº $foo¶ó´Â °á°ú¸¦ ³»³õÀ» °ÍÀÌ´Ù. ±×·¯³ª by the way
ex) foo=10
x=foo
eval y='$' $x
echo $y
ÀÌ°ÍÀº 10À̶ó´Â °á°ú¸¦ ³»³õÀ» °ÍÀÌ´Ù. ÀÌ·¸°Ô evalÀº $¿Í ¾ÆÁÖ
Á¶±Ý ºñ½ÁÇÏ°Ô º¼öÀÇ °©À» ÁÙ°ÍÀÌ´Ù
eval ¸í·ÉÀº Äڵ带 ¸¶À½´ë·Î ±¸»çÇϱâ ÁÁ°Ô ¸¸µå´Â ¸Å¿ì À¯¿ëÇÑ
°ÍÀÌ´Ù. µð¹ö±ë¿£ º¹ÀâÇÏÁö¸¸, °ÅÀÇ ºÒ°¡´ÉÇØ º¸ÀÌ´Â ÀÏÀ»
ó¸®ÇÒ ¼ö ÀÖµµ·Ï µµ¿ÍÁØ´Ù.
exec : ÀÌ ¸í·ÉÀº µÎ°¡Áö ¿ë¹ýÀÌ ÀÖ´Ù. Çϳª´Â ÇöÀç ½©À» ´Ù¸¥
Ç÷α׷¥À¸·Î ´ëüÇÏ´Â ¿ëµµÀÌ´Ù.
exit n : Å»ÃâÄÚµå nÀ¸·Î ½ºÅ©¸³Æ®¸¦ ³¡³¾¶§ »ç¿ëÇÑ´Ù.
»óÈ£ ´ëȽÄÀÇ ½© ¸í·ÉÇà¿¡¼ ÀÌ°ÍÀ» »ç¿ëÇÏ¸é ·Î±×¾Æ¿ô
ÀÌ µÉ°ÍÀÌ´Ù. Á¾·á »óŸ¦ ÁöÁ¤ÇÏÁö ¾Ê°í ½ºÅ©¸³Æ®¸¦
³¡³½´Ù¸é, ¸¶Áö¸· ½ÇÇàµÈ ¸í·ÉÀÇ »óŸ¦ ¹ÝȯÇÒ°ÍÀÌ´Ù
Á¾·áÄڵ带 ÁöÁ¤ÇØÁִ°ÍÀº ÁÁÀº ¹æ¹ýÀÌ´Ù
------------------------------------------
| Á¾·áÄÚµå | ¼³ ¸í |
------------------------------------------
| 126 | ÆÄÀÏÀÌ ½ÇÇàµÇÁö ¾Ê¾Ò´Ù |
------------------------------------------
| 127 | ÇØ´ç ¸í·ÉÀ» ¹ß°ßÇÒ¼ö ¾ø´Ù |
------------------------------------------
| 128ÀÌ»ó | ½Ã±×³ÎÀÌ ¹ß»ýÇß´Ù |
------------------------------------------
export : export´Â º¸Á¶½©¿¡¼ º¯¼ö¸¦ ¸Å°³ ÀÎÀÚ·Î »ï´Â´Ù
±âº»ÀûÀ¸·Î, ½©¿¡¼ »ý¼ºµÈ º¯¼ö´Â ±× ½©¿¡¼ ÆÄ»ýµÈ
(º¸Á¶)½©µé¿¡¼ Á¶Â÷ »ç¿ë ÇÒ¼ö ¾ø´Ù.
´Ù¸¥ ½ºÅ©¸³Æ®³ª ÇöÀç ÇÁ·Î±×·¥¿¡¼ È£ÃâµÈ ÇÁ·Î±×·¥¿¡¼
export¿Í ÇÔ²² ¸Å°³ º¯¼ö¸¦ ÁöÁ¤ÇÏ¿© ȯ°æ º¯¼ö¸¦
»ý¼ºÇÑ´Ù. ´õ Àü¹®ÀûÀ¸·Î ¸»Çϸé, ÇØ´ç ½©¿¡¼ ÆÄ»ýµÈ
Áö½Ä ÇÁ·Î¼¼½º¿¡¼ exportÇÑ È¯°æ º¯¼ö´Â (º»·¡) ½©
¿¡¼ °ü¸®ÇѴٴ°ÍÀÌ´Ù.
¿©±â¿¡ export1°ú export2ÀÇ µÎ°¡Áö ÁÁÀº ¿¹°¡ ÀÕµû
1. export2¸¦ ¸ÕÀú º¸ÀÚ
#!/bin/sh
echo "$foo"
ehoc "$bar"
2. export1ÀÌ´Ù. ÀÌ ½ºÅ©¸³Æ®ÀÇ ¸Ç µÚ¿¡¼ export2¸¦ ºÒ·¯³½´Ù
#!/bin/sh
foo="The first meta-syntactic variable
export bar="The second meta-syntactic variable"
./export2
ÀÌ°ÍÀ» ½ÇÇà½ÃÅ°¸é
[mageoli@linux ~]$./export1
<-- ºóÁÙ
The second meta-syntactic variable
ù¹ø° ºóÁÙÀº fooº¯¼ö°¡ export2¿¡¼ Á¤ÀÇ µÇÁö ¾Ê±â¿¡
¹ß»ýµÈ°ÍÀÌ´Ù. ±×·¡¼ $foo´Â Àǹ̰¡ ¾ø´Â°ÍÀÌ´Ù
echo "$foo" ¸í·ÉÀº ºó ÁÙÀ» Ãâ·ÂÇÑ´Ù.
º¯¼ö V°¡ S ¶ó´Â ½©¿¡¼ exportµÇ¾ú´Ù¸é,º¯¼ö V´Â s¶ó´Â
½©¿¡¼ È£ÃâµÈ ¸ðµç ½ºÅ©¸³Æ®¿Í S ½©¿¡¼ È£ÃâµÈ ¶Ç ´Ù¸¥
S ½©¿¡±îÁö exportµÈ´Ù. À§ÀÇ °æ¿ì¿¡ export2°¡ ´Ù¸¥ ½ºÅ©
¸³Æ®¸¦ È£ÃâÇϸé barº¯¼ö´Â Ç×»ó »ç¿ë °¡´ÉÇÏ´Ù.
expr : expr ¸í·ÉÀº ÀÎÀÚ·Î »ç¿ëµÇ´Â Ç¥Çö½ÄÀÇ °ªÀ» ±¸ÇÑ´Ù.
¾Æ·¡¿Í °°Àº »ê¼ú½Ä¿¡¼ °¡Àå º¸ÆíÀûÀ¸·Î »ç¿ëµÈ´Ù
x = 'expr $x + 1'
-- '<- ÀÌÇ¥½Ã´Â expr $x+1ÀÇ ½ÇÇà °á°ú¸¦ x¿¡ ³Ö´Â ÀÏÀ»
ÇÑ´Ù. ³ªÁß¿¡ ´ëüÇÒ¼ö ÀÖ´Â ¸í·É¿¡ ´ëÇØ ¼³¸í
ÇÏ°ÚµÂ.. --
»ç½Ç exprÀº Ç¥Çö½ÄÀÇ °ªÀ» °è»êÇÏ´Â ¸Å¿ì °·ÂÇÑ ¸í·ÉÀÌ´Ù
Áß¿äÇѰ͸¸ ´ÙÀ½°ú °°ÀÌ ¸ð¾Æ³ù´Ù
--------------------------------------------------------
Ç¥Çö½Ä Æò°¡ : ¼³ ¸í
--------------------------------------------------------
expr 1 | expr2 : expr1ÀÌ 0ÀÌ ¾Æ´Ï¸é expr1, ±×·¸Áö ¾ÊÀ¸¸é
expr2
-------------------------------------------------------
expr1 & expr2 : µÎÇ¥Çö½ÄÀÌ ¸ðµÎ 0À̸é 0, ±×·¸Áö ¾ÊÀ¸¸é
expr1
--------------------------------------------------------
expr1 = expr2 : °°´Ù
--------------------------------------------------------
expr2 > expr2 : ´õÅ©´Ù
--------------------------------------------------------
expr1 >= expr2 : Å©°Å³ª °°´Ù
--------------------------------------------------------
expr1 < expr2 : ÀÛ´Ù
--------------------------------------------------------
expr1 <= expr2 : À۰ųª °°´Ù
--------------------------------------------------------
expr1 != expr2 : °°Áö ¾Ê´Ù
--------------------------------------------------------
expr1 + expr2 : ´õÇϱâ
--------------------------------------------------------
expr1 - expr2 : »©±â
--------------------------------------------------------
expr1 / expr2 : Á¤¼ö ³ª´°¼À¿¡¼ ¸ò±¸Çϱâ
--------------------------------------------------------
expr1 * expr2 : °öÇϱâ
--------------------------------------------------------
expr1 % expr2 : Á¤¼ö ³ª´°¼À¿¡¼ ³ª¸ÓÁö ±¸Çϱâ
--------------------------------------------------------
³ªÁß¿¡ º¸°Ô µÇ°ÚÁö¸¸, ÃÖ±Ù ½ºÅ©¸³Æ®¿¡¼´Â expr ´ë½Å Á»´õ
È¿À²ÀûÀÎ $((..))±¸¹®À» »ç¿ëÇÏ°í ÀÖ´Â Ãß¼¼ÀÌ´Ù
printf : prinft¸í·ÉÀº °¡Àå ÃÖ±ÙÀÇ ½©¿¡¼¸¸ »ç¿ë °¡´ÉÇÏ´Ù
X/OpenÀº Çü½ÄÈµÈ Ãâ·ÂÀ» »ý¼º ÇÒ¶§ echo°¡ ¾Æ´Ñ
printf¸¦ »ç¿ëÇÏ¿©¾ß ÇÑ´Ù°í ±ÔÁ¤ÇÏ°í ÀÖ´Ù
Çü½Ä) printf "format string" parameter1 parmeter2 ...
Á¶±Ý Á¦ÇÑÀûÀ̱ä ÇÏÁö¸¸ "format string" Àº C³ª C++
¿¡¼ »ç¿ëÇÏ´Â °Í°ú ¸Å¿ì ºñ½ÁÇÏ´Ù.
--------------------------------------------------------
º¯È¯ ½Äº°ÀÚ : ¼³ ¸í
--------------------------------------------------------
d : ½ÊÁø¼ö Ãâ·Â
--------------------------------------------------------
c : ÇÑ ¹®ÀÚ Ãâ·Â
--------------------------------------------------------
s : ¹®Àå Ãâ·Â
--------------------------------------------------------
% : % ¹®ÀÚ Ãâ·Â
--------------------------------------------------------
printf´Â format stringÀÇ ³ª¸ÓÁö ¸Å°³ º¯¼ö¸¦ Çؼ®ÇÑ´Ù.
[mageoli@linux ~]$printf "%s\n" hello
hello
[mageoli@linux ~]$printf "%s %d\t%s" "HI There" 15 people
HI There 15 people
" " ·Î ¹ÀÎ Hi There¶ó´Â ¹®ÀåÀÌ ÇϳªÀÇ ¸Å°³ º¯¼öÀÌ´Ù
set : set¸í·ÉÀº ½©¿¡¼ ¸Å°³ ÀÎÀÚ¸¦ ¼³Á¤ÇÑ´Ù
¾î¶°ÇÑ ¹®ÀÚ¿À» °ø¹éÀ¸·Î ³ª´©¾îÁø Çʵå·Î Ãâ·ÂÇÒ¶§
¾ÆÁÖ À¯¿ëÇÏ´Ù
½© ½ºÅ©¸³Æ®¿¡¼ À̹ø´ÞÀÇ À̸§À» »ç¿ëÇÑ´Ù°í °¡Á¤Çغ¸ÀÚ
½Ã½ºÅÛÀº ¹®ÀÚ·Î µÈ ´ÞÀ» Æ÷ÇÔÇÏ´Â date¶ó´Â ¸í·ÉÀ»
Á¦°øÇÏÁö¸¸ ¿ì¸®´Â ±×Áß ÀϺκи¸ ÇÊ¿äÇÏ´Ù.
$(...)±¸¹®ÀÇ Á¶ÇÕÀ» »ç¿ëÇؼ °á°ú°ªÀ» ¸®ÅϹްí set
¸í·ÉÀ» ¼öÇàÇÑ´Ù. date¸í·ÉÀÇ Ãâ·Â¿¡¼ µÎ¹ø° ÀÎÀÚ°¡
´ÞÀ» ³ªÅ¸³»´Â ¹®ÀÚ¿ÀÌ´Ù ¹ØÀÇ ¿¹¸¦ Âü°íÇϱ⠹ٶõ´Ù
#!/bin/sh
echo the eate is $(date)
set $(date)
echo The month is $2
exit 0
°á°ú)
[mageoli@linux ~]$./test
the eate is 2002. 02. 06. (¼ö) 13:13:07 KST
The month is 02.
[mageoli@linux ~]$
shitf : shift¸í·ÉÀº $2¸¦ $1À¸·Î $3À» $2·Î À̵¿½ÃŲ´Ù.
Áï, ¸ðµç ¸Å°³ º¯¼ö¸¦ ÇÑ Ä ¾Æ·¡·Î À̵¿½ÃŲ´Ù
ÀÌÀüÀÇ $1°ªÀº ¹«½ÃµÇ¸ç, $0¸¸ º¯ÇÏÁö ¾Ê´Â´Ù
trap : trapÀº ½©¿¡¼ ¸í·ÉÀÇ ½ÇÇ൵Áß ¹Þ´Â ½Ã±×³ÎÀ» ó¸®ÇÏ´Â
½Ã±×³Î 󸮱⸦ ¸¸µå´Â ¿ªÇÒÀ» ÇÑ´Ù. °¡·É ½©À̳ª ½©
½ºÅ©¸³Æ®¿¡¼ ÀÓ½ÃÆÄÀÏÀ» ¸¸µé¾î¼ »ç¿ëÇÏ´Â °¡¿îµ¥
ƯÁ¤ ½Ã±×³ÎÀ» ¹Þ°Ô µÉ¶§ Àӽà ÆÄÀÏÀ» Áö¿ì°í Á¾·áÇϵµ·Ï
ÇÒ¼öÀÖ´Ù. ½Ã±×³ÎµéÀ» º¸·Á¸é trap -lÀ» ÀÔ·ÂÇÏ¸é µÈ´Ù
trap¸í·É¿¡ ƯÁ¤ ½Ã±×³ÎÀ» ¹Þ°Ô µÉ¶§ ÃëÇÒ ¸í·É°ú ÇØ´ç ½Ã±×³ÎÀ»
ÁöÁ¤ÇÑ´Ù
Çü½Ä ) trap command signal
º¸Åë ½ºÅ©¸³Æ®´Â À§¿¡¼ ¾Æ·¡·Î Çؼ®µÇ±â ¶§¹®¿¡ º¸È£ÇÒ ºÎºÐ
ÀÌÀü¿¡ trap ¸í·ÉÀ» »ç¿ëÇØ¾ß ÇÑ´Ù
X/Open¿¡¼ Ç¥ÁØÀ¸·Î Á¤ÇÑ, Æ÷Âø °¡´ÉÇÑ Áß¿äÇÑ ½Ã±×³ÎÀÌ´Ù
--------------------------------------------------------
½Ã±×³Î : ¼³ ¸í
--------------------------------------------------------
HUP(1) : ²÷±â(hang up); º¸Åë Å͹̳ο¡¼ ¿¬°áÀÌ
²÷¾îÁö°Å³ª »ç¿ëÀÚ°¡ ·Î±×¾Æ¿ô ÇßÀ»¶§
º¸³½´Ù.
--------------------------------------------------------
INT(2) : ÀÎÅÍ·´Æ®(interrupt); º¸Åë Ctrl-C¸¦
´·¶À»¶§ º¸³½´Ù
--------------------------------------------------------
QUIT(3) : Á¾·á(quit); º¸Åë Ctrl-\¸¦ ´·¶À»¶§º¸³½´Ù
--------------------------------------------------------
ABRT(6) : ÁßÁö(abort); º¸Åë Ä¡¸íÀûÀÎ ½ÇÇà ¿¡·¯°¡
¹ß»ýÇßÀ»¶§ º¸³½´Ù
--------------------------------------------------------
ALRM(14) : ¾Ë¶÷(alarm);º¸Åë ÁöÁ¤ÇÑ ½Ã°£ÀÌ Áö³µÀ»¶§
¹ß»ý½ÃŲ´Ù.
--------------------------------------------------------
TERM(15) : Áß´Ü(terminate);º¸Åë½Ã½ºÅÛÀÌ ¼Ë´Ù¿î µÉ¶§
½Ã½ºÅÛÀÌ º¸³»°Ô µÈ´Ù
--------------------------------------------------------
¹é¹®ÀÌ ºÒ¿© ÀÏ°ßÀÌ·¨µÂ.. ÇÔ ¿¹Á¦¸¦ º¸¸ç ´À²¸º¸ÀÚ
ex)
#!/bin/sh
trap 'rm -f ~/test1/test' INT
echo creating file ~/test1/test
date > ~/test1/test
echo "Press interrupt (Ctrl-C) to interrupt ...."
while [ -f ~/test1/test ]; do
echo File exists
sleep 1
done
echo The file no longer exists
./trap -INT
echo creating file ~/test1/test
date > ~/test1/test
echo "Press interrupt (Ctrl-C) to interrupt...."
while [ -f ~/test1/test ]; do
echo File exitst
sleep 1
done
echo We never get here
exit 0
ÀÌ ½ºÅ©¸³Æ®´Â trap ¸í·ÉÀ» »ç¿ëÇؼ INT½ÅÈ£°¡ ¹ß»ýÇϸé
'rm -f ~/test1/test'¸¦ ½ÇÇàÇÏ°Ô µÈ´Ù. while ·çÇÁ¸¦ µ¹¸®¸é¼
ÆÄÀÏÀÇ Á¸ÀçÀ¯¹«¸¦ È®ÀÎÇÑ´Ù. Ctrl-C¸¦ ´©¸£¸é rm -f ~/test1/test
°¡ ½ÇÇàµÇ¸ç while ·çÇÁ´Â ´Ù½Ã Àç°³µÈ´Ù. ÆÄÀÏÀº ÀÌÁ¦ Áö¿ö
|