¼ø¶È»ñÎÁ/07

What are shell scripts?: ¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤È¤Ï

JNorth_arrow-right-sm.png ¥¹¥¯¥ê¥×¥È¥Õ¥¡¥¤¥ë¤Î¥³¥Þ¥ó¥É²½ ¤òÍøÍѤ·¤Æ¡¤¥·¥§¥ë¤ÎÁàºî¤ò°ì¤Ä¤Î¥³¥Þ¥ó¥É¤ËÊѤ¨¤ë¤â¤Î¤Ç¤¢¤ë¡¥
Unix ¤Ç²¿²ó¤â»÷¤¿¤è¤¦¤Êºî¶È¤ò¤¹¤ë¤È¤­¤Ê¤É¤Ë¤Ï¡¤Èó¾ï¤Ë°ÒÎϤòȯ´ø¤¹¤ë¡¥



·«¤êÊÖ¤¹Áàºî¤Ï¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤Ç
¥³¥Þ¥ó¥É¤Ë¤·¤Æ¤É¤ó¤É¤ó¸úΨ¤è¤¯¡ª¡ª

¥·¥§¥ë¤Îʸˡ¤Ë´Ø¤·¤Æ¤Ï¡¤sh ·Ï¥·¥§¥ë¤È csh ·Ï¥·¥§¥ë¤Ç·ë¹½°ã¤¦¡¥

  • csh ·Ï¤ÎÊý¤¬¿Í´Ö¤Ë¤È¤Ã¤Æľ´¶Åª.
  • bsh ·Ï¤ÎÊý¤¬¤­¤Á¤ó¤È¤·¤Æ¤¤¤ë ( warning.png "Í­³²¤Ê csh ¥×¥í¥°¥é¥ß¥ó¥°" ¤È¤¤¤¦Ê¸¸À¤òweb¤Ç¸¡º÷¤·¤Æ¤ß¤è¤¦)



º£²ó¤Ï bsh ·Ï¤Ç³Ø½¬¤·¤Æ¤ª¤¯.

ÆâÍƤÎÏäò¤¹¤ëÁ°¤Ë¡Ä

¥·¥§¥¹¥¹¥¯¥ê¥×¥È¤Ë¤Ä¤¤¤Æ³Ø¤ó¤À¤ê¡¤¼«Ê¬¤Ç¥¹¥¯¥ê¥×¥È¤ò½ñ¤¤¤¿¤ê¤·¤Æ¤¤¤ë¤È¤¤¤í¤¤¤íµ¿Ì䤬À¸¤º¤ë¤È»×¤¦¡¥ ¤½¤ÎºÝ¡¤¥¹¥¯¥ê¥×¥È¤òÆþ¤ì¤ë¤È²òÀâ¤ò¤·¤Æ¤¯¤ì¤ë
JNorth_arrow-right-sm.png www.shellcheck.net
¤ÏÂçÊÑÌò¤ËΩ¤Ä¤À¤í¤¦¡¥ ¤¼¤ÒÍ­¸ú³èÍѤ·¤Æ¤â¤é¤¤¤¿¤¤¡¥



Preparation and rough explanation: ½àÈ÷¤È°ìÏ¢¤Îή¤ì

Preparation: ½àÈ÷

  1. ¥¹¥¯¥ê¥×¥È¥Õ¥¡¥¤¥ë¤òÃù¢¤·¤Æ¤ª¤¯¥Ç¥£¥ì¥¯¥È¥ê¤òÍÑ°Õ¡¥ bin ¤È¤¤¤¦Ì¾Á°¤òÍѤ¤¤ë¤³¤È¤¬Â¿¤¤¡¥

    cd␣~

    mkdir␣bin


  2. ÍÑ°Õ¤·¤¿¥Ç¥£¥ì¥¯¥È¥ê¤Ë path ¤òÄ̤¹¡¥.profile ¤ÎÃæ¤ÇÀßÄꤹ¤ë¤Î¤¬Îɤ¤¤À¤í¤¦¡¥ ¶ñÂÎŪ¤Ë¤Ï¡¤~/.profile ¤ÎÃæ¤Î¤½¤ì¤Ã¤Ý¤¤¤È¤³¤í¤Ë
    1. if [ -d $HOME/bin ]
    2.   then
    3.   PATH=$PATH:$HOME/bin; export PATH
    4. fi
    ¤Ê¤É¤È½ñ¤­¹þ¤ó¤Ç¤ª¤±¤Ð¡¤¼¡²ó¥í¥°¥¤¥ó»þ¤è¤ê¤³¤ì¤¬Í­¸ú¤Ë¤Ê¤ë¡¥
    warning.png [ ¤ä ] ¤ÎÁ°¸å¤ËÆþ¤Ã¤Æ¤¤¤ë¥¹¥Ú¡¼¥¹¤ò½üµî¤·¤Ê¤¤¤³¤È¡ª ¤³¤ì¤é¤Ï°ìʸ»ú¤À¤¬¡¤¥³¥Þ¥ó¥É¤Ê¤Î¤À¡¥
    warning.png ¤³¤ÎÊѹ¹¤òÍ­¸ú¤Ë¤¹¤ë¤¿¤á¤Ë¤¤¤Ã¤¿¤ó¥í¥°¥¢¥¦¥È¤·¤Æ¤«¤éºÆ¥í¥°¥¤¥ó¤·¤Æ¤â¤è¤¤¤¬¡¤

    source␣~/.profile

    ¤ÈÆþÎϤ¹¤ë¤È¤½¤Î¾ì¤Ç.profile¥Õ¥¡¥¤¥ë¤ÎÃæ¿È¤¬È¿±Ç¤µ¤ì¤ë¤Î¤Ç¤½¤ì¤Ç¤â¤è¤¤¡¥

notes.png ¼Â½¬: ¾å¤Î½àÈ÷ 1, 2 ¤ò¤·¤Æ¤ª¤³¤¦¡¥ ¤¿¤À¤·¡¤ºåÂç¤Î´Ä¶­¤Ç¤ÏºÆ¥í¥°¥¤¥ó¤·¤¿»þ¤Ë .profile ¤ÎÆâÍƤ¬È¿±Ç¤µ¤ì¤Ê¤¤¤«¤â¤·¤ì¤Ê¤¤¡¥ ¤½¤Î¾ì¹ç¤Ï¡¤¥í¥°¥¤¥ó¤·¤¿¤é¾å¤Îsource¤ò»È¤¦ÊýË¡¤Ç path ¤ò(Ëè²ó¡©)ºÆÀßÄꤷ¤è¤¦¡¥

Rough explanation: ¥·¥§¥ë¥¹¥¯¥ê¥×¥ÈÍøÍѤΰìÏ¢¤Îή¤ì

¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤òºî¤Ã¤Æ¡¤¤½¤·¤Æ»È¤¦¤Ë¤Ï¤¤¤Ä¤â°Ê²¼¤ÎÆóÃʳ¬¤òƧ¤ó¤Ç¤ª¤±¤ÐÎɤ¤¡¥

  1. ¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤òºî¤ê¡¤1 ¤ÇÍÑ°Õ¤·¤¿¥Ç¥£¥ì¥¯¥È¥ê¤ËÃÖ¤¯.

  2. ¥¹¥¯¥ê¥×¥È¥Õ¥¡¥¤¥ë¤Ë¼Â¹Ôµö²Ä¤òÍ¿¤¨¤ë¡¥
    Î㤨¤Ð¡¤¥¹¥¯¥ê¥×¥È¥Õ¥¡¥¤¥ë¤¬ dummy ¤È¤¤¤¦Ì¾Á°¤Ê¤é¤Ð

    chmod␣u+x␣~/bin/dummy

    ¤È¤¹¤ì¤ÐÎɤ¤¡¥



Basic structure of shell scripts: ¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤Î´ðËܹ½Â¤(bash)

JNorth_arrow-right-sm.png ¥¹¥¯¥ê¥×¥È¥Õ¥¡¥¤¥ë¤Î¥³¥Þ¥ó¥É²½ ¤òÍѤ¤¤Æ¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤ÏºîÀ®¤µ¤ì¤ë¡¥ ¥¹¥¯¥ê¥×¥È¤ÎÀèƬ¹Ô¤Ë¤É¤¦½ñ¤¯¤«¤Ç¤¢¤ë¤¬¡¤linux ·Ï¤Ç¤¢¤ì¤Ð

#!/bin/sh

¤È½ñ¤±¤ÐÎɤ¤¤À¤í¤¦¡¥



warning.png ¥¹¥¯¥ê¥×¥È¤ÎÆâÍƤò¼Â¹Ô¤·¤Ê¤¤¤Ç¡¤Ê¸Ë¡¥Á¥§¥Ã¥¯¤À¤±¹Ô¤¤¤¿¤¤¾ì¹ç¤Ï¡¤

#!/bin/sh␣-n

¤ÈÀèƬ¹Ô¤Ë½ñ¤±¤Ð¤è¤¤¡¥ ¥Õ¥¡¥¤¥ë¤Îºï½ü¤Ê¤É¡¤¤ä¤ä´í¸±¤Êºî¶È¤ò¹Ô¤¦¥¹¥¯¥ê¥×¥È¤Ï¤³¤ì¤Ç¥Á¥§¥Ã¥¯¤¹¤ë¤ÈÎɤ¤¤À¤í¤¦¡¥



warning.png ¼Â¹Ô»þ¤Ë¥¹¥¯¥ê¥×¥È¤ÎÆâÍƤâɽ¼¨¤·¤¿¤¤¾ì¹ç¤Ï¡¤

#!/bin/sh␣-v

¤ÈÀèƬ¹Ô¤Ë½ñ¤±¤Ð¤è¤¤¡¥ ¥¹¥¯¥ê¥×¥È¤ÎÆ°ºî¤¬Ë¾¤ß¤Î¤â¤Î¤È°ã¤¦»þ¤Ï¤³¤ì¤Ç¥Á¥§¥Ã¥¯¤¹¤ë¤ÈÎɤ¤¡¥



notes.png ¼Â½¬

  1. Hello ¤È¤¤¤¦¥Õ¥¡¥¤¥ë̾¤Ç¡¤¼¡¤Î¤è¤¦¤ÊÃæ¿È¤Î¥¹¥¯¥ê¥×¥È¤òºî¤ë.
    1. #!/bin/sh
    2. echo "Hello, world!"

  2. ¾å¤Î JNorth_arrow-right-sm.png °ìÏ¢¤Îή¤ì¤Î 1,2 ÁêÅö¤ò¹Ô¤ª¤¦¡¥

  3. ¤É¤Î¥Ç¥£¥ì¥¯¥È¥ê¤«¤é¤Ç¤â¤è¤¤¤Î¤Ç¡¤

    Hello

    ¤ÈÂǤÁ¹þ¤ó¤Ç¡¤ºîÀ®¤·¤¿¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤¬Æ°ºî¤¹¤ë¤³¤È¤ò³Îǧ¤·¤è¤¦¡¥



Continuous execution of commands: ¥³¥Þ¥ó¥É¤ÎϢ³¼Â¹Ô

¥³¥Þ¥ó¥É¤ÎϢ³¼Â¹ÔÅù¤Ë¤Ä¤¤¤Æ JNorth_arrow-right-sm.png Ϣ³¼Â¹Ô ¤ÎÉôʬ¤Ç³Ø½¬¤·¤¿¤¬¡¤¤³¤³¤Ç¾ðÊó¤òÄɲ䷤Ƥª¤¯¡¥

¥³¥Þ¥ó¥É1␣;␣¥³¥Þ¥ó¥É2
¥³¥Þ¥ó¥É1 ¤ò¼Â¹Ô¸å¡¤¥³¥Þ¥ó¥É2 ¤ò¼Â¹Ô¤¹¤ë¡¥
( ¥³¥Þ¥ó¥É1␣;␣¥³¥Þ¥ó¥É2 )
¥³¥Þ¥ó¥É1 ¤ò¼Â¹Ô¸å¡¤¥³¥Þ¥ó¥É2 ¤ò¼Â¹Ô¤¹¤ë¡Ä ¤Î¤À¤¬¡¤ ¤³¤ì¤éÆó¤Ä¤Î¥³¥Þ¥ó¥É¤ò¡Ö¥µ¥Ö¥·¥§¥ë¡×¤Î¤â¤È¤Ç¼Â¹Ô¤¹¤ë(¥°¥ë¡¼¥×²½)¡¥ ¥µ¥Ö¥·¥§¥ë¤Ç¹Ô¤Ã¤¿´Ä¶­Êѹ¹¤Ï¤â¤È¤Î¥·¥§¥ë¤Ë±Æ¶Á¤·¤Ê¤¤¡¥ ¤è¤Ã¤Æ¡¤¾õÂÖ¤ò°ì»þŪ¤ËÊѹ¹¤·¤Æºî¶È¤¹¤ë¤È¤­¤ËÊØÍø¡¥

Gnome-Preferences.png ¥°¥ë¡¼¥×²½¤ÎÎã.
Î㤨¤Ð¡¤

(cd␣/tmp;␣ls␣-a)

¤È¤¹¤ë¤È¡¤/tmp ¤Çºî¶È¤¬¹Ô¤ï¤ì¤ë¤¬¡¤½ª¤ï¤Ã¤¿¤¢¤È¤Ë¥Ç¥£¥ì¥¯¥È¥ê¤ÏÊѹ¹¤µ¤ì¤Æ¤¤¤Ê¤¤¡¥

¤Þ¤¿¡¤¥°¥ë¡¼¥×²½¤·¤¿¥³¥Þ¥ó¥É¤Îɸ½à½ÐÎÏÅù¤Ï¡Ö¹ç¤ï¤µ¤Ã¤Æ¡×½Ð¤Æ¤¯¤ë¡¥ ¤³¤ì¤¬ÊØÍø¤Ê¤³¤È¤â¿¤¤¡¥

Gnome-Preferences.png ¥°¥ë¡¼¥×²½¤ÎÎã2.
Î㤨¤Ð¡¤

(\ls␣/tmp;␣\ls␣/var)␣|␣less

¤È¤¹¤ë¤È¡¤/tmp ¤È /var ¤Î2¤Ä¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ë¤¢¤ë¥Õ¥¡¥¤¥ë¤Î¥ê¥¹¥È¤ò°ìÅ٤˱ÜÍ÷¤Ç¤­¤ë¡¥
¥³¥Þ¥ó¥É1␣&&␣¥³¥Þ¥ó¥É2
AND ¼Â¹Ô¡¥ ¥³¥Þ¥ó¥É1 ¤ò¼Â¹Ô¤·¤Æ¤ß¤Æ¡¤¥³¥Þ¥ó¥É1 ¤¬À®¸ù¤·¤¿¤Ê¤é¤Ð(¥¨¥é¡¼¤Ë¤Ê¤é¤Ê¤¤»þ)¡¤ ¥³¥Þ¥ó¥É2 ¤ò¼Â¹Ô¤¹¤ë¡¥
¥³¥Þ¥ó¥É1␣¦¦␣¥³¥Þ¥ó¥É2
OR ¼Â¹Ô¡¥ ¥³¥Þ¥ó¥É1 ¤ò¼Â¹Ô¤·¤Æ¤ß¤Æ¡¤¥³¥Þ¥ó¥É1 ¤¬¼ºÇÔ¤·¤¿¤Ê¤é¤Ð(¥¨¥é¡¼¤Ë¤Ê¤Ã¤¿»þ)¡¤ ¥³¥Þ¥ó¥É2 ¤ò¼Â¹Ô¤¹¤ë¡¥



Grammer of shell scripts: ¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤Îʸˡ

Comment out: ¥³¥á¥ó¥È¥¢¥¦¥È

¥·¥§¥ë¥¹¥¯¥ê¥×¥ÈÃæ¤Ç # ¤È¤¤¤¦Ê¸»ú¤¬¤¢¤ë¤È¡¤ ¤½¤³¤«¤é¹ÔËö¤Þ¤Ç¤¬¥³¥á¥ó¥È¤È¤·¤Æ¼è¤ê°·¤ï¤ì¤ë(¤¿¤À¤·¡¤Ê¸»úÎóÃæ¤Ï½ü¤¯)¡¥

Variables: ÊÑ¿ô

JNorth_arrow-right-sm.png ¥·¥§¥ëÊÑ¿ô ¤Ç³Ø¤ó¤À¤È¤ª¤ê¤Ë¡¤¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤ÇÊÑ¿ô¤¬»È¤¨¤ë¡¥

warning.png ÊÑ¿ôÀßÄê¤Î¤È¤­¡¤ÊÑ¿ô̾¤È¡Ö=¡×¤Î´Ö¤Ë¥¹¥Ú¡¼¥¹¤òÆþ¤ì¤ë¤Ê¡ª


warning.png ¼Â¤Ï¡¤ÊÑ¿ô»²¾È¤ÎºÝ¤Ë

${ÊÑ¿ô̾}

¤È¤·¤¿Êý¤¬¡¤¤è¤ê°ÂÁ´¤À¡¥



String: ʸ»úÎó

ʸ»úÎó¤Ï quotation ¤Çɽ¤¹¡¥
¤³¤Î»þ¡¤ ¡Ö'¡×(¥·¥ó¥°¥ë¥¯¥©¡¼¥È) ¤Ç°Ï¤à¤Î¤È¡¤ ¡Ö"¡×(¥À¥Ö¥ë¥¯¥©¡¼¥È) ¤Ç°Ï¤à¤Î¤Ç¤ÏÀ­¼Á¤¬°Û¤Ê¤ë¤Î¤ÇÃí°Õ¤¬É¬ÍפÀ¡¥

¡Ö'¡×(¥·¥ó¥°¥ë¥¯¥©¡¼¥È) ¤Ç°Ï¤ó¤Àʸ»úÎó
²¿¤¬½ñ¤«¤ì¤Æ¤¤¤Æ¤âñ¤Ê¤ëʸ»úÎó¤È¤·¤Æ°·¤¦¡¥

¡Ö"¡×(¥À¥Ö¥ë¥¯¥©¡¼¥È) ¤Ç°Ï¤ó¤Àʸ»úÎó
$ ` \ ¤Î3¤Ä¤ÎÆüìʸ»ú¤ò¤³¤ì¤Þ¤Ç³Ø¤ó¤ÀÆüì¤Ê°ÕÌ£¤Ç°·¤¦. ¤Ä¤Þ¤ê¡¤"(¥À¥Ö¥ë¥¯¥©¡¼¥È)¤Ç°Ï¤Þ¤ì¤¿Ê¸»úÎó¤ÎÃæ¤ÇÊÑ¿ô¤Î»²¾È¤Ï¹Ô¤ï¤ì¤ë. "(¥À¥Ö¥ë¥¯¥©¡¼¥È) ¤Î°Ï¤ßÆâÉô¤Ç¾å¤Î3¤Ä¤ÎÆüìʸ»ú¤òñ¤Ê¤ëʸ»ú¤È¤·¤Æ°·¤¤¤¿¤±¤ì¤Ð¡¤ \ ¤òÁ°¤Ë¤Ä¤±¤Æ \$ \` \\ ¤È¤¹¤ë¡¥



notes.png ¼Â½¬

Àè¤Î Hello ¥¹¥¯¥ê¥×¥È¤ò¼¡¤Î¤è¤¦¤Ë²þ¤¤·¤è¤¦.

  1. #!/bin/sh
  2. # Greeting Script
  3. g='Hello, world!'
  4. d="today is `date +%m/%d`"
  5. echo $g, $d.

¤½¤·¤Æ¡¤²¿¤¬¤É¤¦¤Ê¤Ã¤Æ¤¤¤ë¤Î¤«Íý²ò¤·¤è¤¦¡¥



Arguments: °ú¿ô

°ú¿ô¤È¤Ï¡¤¥×¥í¥°¥é¥à¤òµ¯Æ°¤¹¤ë¤È¤­¤Ë¡¤°ì½ï¤ËÍ¿¤¨¤ë¾ðÊó¤Ç¤¢¤ë¡¥ Î㤨¤Ð ls␣-a␣/tmp ¤È¥×¥í¥°¥é¥à¤ò¼Â¹Ô¤·¤¿¤é¡¤(¹­¤¤°ÕÌ£¤Ç)°ú¿ô¤Ï -a, /tmp ¤ÎÆó¤Ä¤Ç¤¢¤ë¡¥
¤³¤Î°ú¿ô¤Ï°Ê²¼¤Î¤è¤¦¤Ë°·¤ï¤ì¤ë¡¥

¢£ sh ·Ï¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤Ç¤Î°ú¿ô¤Î°·¤¤ ¢£
ÊÑ¿ô°ÕÌ£
$#°ú¿ô¤Î¸Ä¿ô
$nn ÈÖÌܤΰú¿ô¡¥
¤¿¤À¤·¡¤0ÈÖÌܤΰú¿ô $0 ¤ÏÆÃÊ̤ǡ¤¥·¥§¥ë¥¹¥¯¥ê¥×¥È¼«¿È¤Î̾Á°¤Ë¤Ê¤ë¡¥

¤Þ¤¿¡¤n > 9 ¤Ç¤¢¤ë¾ì¹ç¤Ï ${12} ¤Ê¤É¤È¡¤Ã楫¥Ã¥³¤Ç°Ï¤Þ¤Ê¤¤¤È»È¤¨¤Ê¤¤¡¥
$*°ú¿ôÁ´¤Æ¡¥
(»²¹Í) $argv{m-n}m ÈÖÌܤ«¤é n ÈÖÌܤޤǤΰú¿ô¤Î»ØÄê. ¤¿¤À¤· sh·Ï¤Ç¤ÏÍ­¸ú¤Ç¤Ï¤Ê¤¤¤è¤¦¤À¡¥ bash ¤Ê¤É¤Ç¤Ï¡¤°ú¿ô¤ÎÊ£»¨¤Ê½èÍý¤Ï getopts ¤Ç¹Ô¤¦¤Î¤¬Îɤ¤¤À¤í¤¦¡¥

Argument ¤ÎÁàºî: shift ¥³¥Þ¥ó¥É

shift ¤È¤¤¤¦¥³¥Þ¥ó¥É¤ò¼Â¹Ô¤¹¤ë¤È¡¤ °ì¤ÄÌܤΥª¥×¥·¥ç¥ó¤ÎÆâÍƤ¬¾Ãµî¤µ¤ì¡¤Æó¤ÄÌܰʹߤ¬Á°¤Ë¤º¤ì¤ë¡¥ ¸À¤¤´¹¤¨¤ë¤È¡¤ $1 ¤Ë $2 ¤ÎÆâÍƤ¬Æþ¤ê¡¤ $2 ¤Ë $3 ¤ÎÆâÍƤ¬Æþ¤ê¡Ä ¤È ¤¤¤Ã¤¿Æ°ºî¤Ë¤Ê¤ë¡¥ ¤Þ¤¿¡¤¤³¤Î·ë²Ì¤È¤·¤Æ¥ª¥×¥·¥ç¥ó¤Î¿ô $# ¤Ï 1 ¸º¤ë¡¥



notes.png ¼Â½¬

Welcome ¤È¤¤¤¦¥Õ¥¡¥¤¥ë̾¤Ç¥¹¥¯¥ê¥×¥È¤ò¼¡¤Î¤è¤¦¤Ëºî¤ë.

  1. #!/bin/sh
  2. # Welcome Script
  3. name=`whoami`
  4. g="($1 says) Thank you, $name"
  5. echo $g.

¤½¤·¤Æ¡¤¤³¤Î¥¹¥¯¥ê¥×¥È¤ò¼¡¤Î¤è¤¦¤Ë¼Â¹Ô¤·¤Æ¤ß¤è¤¦.

Welcome␣Smith

¼Â¹Ô¤·¤Æ¤ß¤è¡¥ ¤½¤·¤Æ¡¤¥¹¥¯¥ê¥×¥È¤ÎÆâÍƤòÆɤó¤ÇÍý²ò¤»¤è.



I/O: Æþ½ÐÎÏ

¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤¬¼Â¹ÔÃæ¤ËÆþ½ÐÎϤò¹Ô¤¦¤Ë¤Ï¡¤¼ç¤Ë¼¡¤Î¥³¥Þ¥ó¥É¤òÍѤ¤¤ë¡¥

read␣ÊÑ¿ô
ÆþÎÏ¡¥
¥æ¡¼¥¶¤«¤é¤Î(¥­¡¼¥Ü¡¼¥É)ÆþÎϤòÂÔ¤Á¡¤¤½¤Î·ë²Ì¤òÊÑ¿ô¤Ë¤¤¤ì¤ë¡¥
echo␣½ÐÎϤ·¤¿¤¤¤â¤Î
½ÐÎÏ
echo␣-n␣½ÐÎϤ·¤¿¤¤¤â¤Î
½ÐÎÏ¡¥¤¿¤À¤·¡¤½ÐÎϸå¤Ë²þ¹Ô¤·¤Ê¤¤¡¥

Gnome-Preferences.png ¼Â¹ÔÎã¡¥

  1. #!/bin/sh
  2. echo -n 'Pls input something : '
  3. read a
  4. echo ' You input is ' $a

¤ò¼Â¹Ô¤¹¤ë¤È¤É¤¦¤Ê¤ë¤À¤í¤¦¤«¡¥



notes.png ¼Â½¬

Hello ¥¹¥¯¥ê¥×¥È¤ò¤µ¤é¤Ë²þ¤¤·¤Æ¼¡¤Î¤è¤¦¤Ë¤·¤è¤¦.

  1. #!/bin/sh
  2. # Greeting Script
  3. g='Hello'
  4. i='Please tell me your name: '
  5. o="Oh, nice to meet you"
  6. echo $g.
  7. echo -n $i
  8. read ans
  9. echo $o, $ans.

¤½¤·¤Æ¡¤¤³¤Î¥¹¥¯¥ê¥×¥È¤ò¼Â¹Ô¤·¤Æ¤ß¤ë¤È¤È¤â¤Ë¡¤²¿¤¬¤É¤¦¤Ê¤Ã¤Æ¤¤¤ë¤Î¤«Íý²ò¤»¤è.



Calculations: ·×»»

¤½¤³¤½¤³¿·¤·¤¤ bash ¤Ï¤È¤â¤«¤¯¡¤ ¥ª¥ê¥¸¥Ê¥ë¤Î sh ¤Ï·×»»µ¡Ç½¤ò¤Û¤È¤ó¤É»ý¤Ã¤Æ¤¤¤Ê¤¤¡¥
¤½¤³¤Ç¡¤¥·¥§¥ë¥¹¥¯¥ê¥×¥ÈÃæ¤Ç·×»»¤ò¹Ô¤¤¤¿¤¤¤È¤­¤Ï¸ß´¹À­¤ò´Õ¤ß¤Æ JNorth_arrow-right-sm.png ÊØÍø¡ªÀèÆɤßɾ²Á `` ¤òÍøÍѤ·¤Æ³°Éô¥³¥Þ¥ó¥É¤ò¸Æ¤Ó½Ð¤¹¤Ê¤É¤ÎÊýË¡¤¬ºÎ¤é¤ì¤ë¤³¤È¤¬Â¿¤¤¡¥
¶ñÂÎŪ¤Ë¤Ï¡¤´Êñ¤ÊÀ°¿ô·×»»¤À¤±¤Ç¤è¤±¤ì¤Ð expr ¤ò¡¤ ¤ä¤äÊ£»¨¤Ê¼Â¿ô·×»»¤ò¹Ô¤¤¤¿¤±¤ì¤Ð bc ¤Ê¤É¤ò»È¤Ã¤Æ¼¡¤ÎÎã¤Î¤è¤¦¤Ë¤¹¤ë¡¥

Gnome-Preferences.png expr ¤ò»È¤Ã¤¿Îã

  1. #!/bin/sh  
  2. a=5
  3. b=`expr $a + 10` ; echo $b
  4. c=`expr $b \* 2` ; echo $c

warning.png ºÇ¸å¤Î¹Ô¤Î ` ` ¤ÎÃæ¤Ç¡¤* ¤ÏŸ³«¤µ¤ì¤Æ¥Õ¥¡¥¤¥ë̾¤Ê¤É¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¤¤«¤Í¤Ê¤¤¤Î¤Ç¡¤\* ¤È¤·¤Æ(¥¨¥¹¥±¡¼¥×)¡¤Ã±¤Ê¤ëʸ»ú¤È¤·¤Æ¤¤¤ë¡¥

notes.png ¼Â½¬

¾å¤Î¥¹¥¯¥ê¥×¥È¤ò»î¤·¤Æ¤ß¤è.



Gnome-Preferences.png bc ¤ò»È¤Ã¤¿Îã

bc ¤Ï¡¤É¸½àÆþÎϤ«¤é·×»»¼°¤ò¤â¤é¤Ã¤Æ·ë²Ì¤òɸ½à½ÐÎϤ˽Ф»¤ë¤Î¤Ç¡¤Î㤨¤Ð echo ¤Ç¼°¤òÅϤ»¤ÐÎɤ¤¡¥

  1. #!/bin/sh  
  2. a=`echo "4*a(1.0)" | bc -l` ; echo $a
  3. b=`echo "c($a)" | bc -l` ; echo $b

¤Á¤Ê¤ß¤Ë¡¤2¹ÔÌÜ¤Ç ¦Ð¤ò¡¤3¹ÔÌÜ¤Ç cos(¦Ð) ¤ò·×»»¤·¤Æ¤¤¤ë¡¥

notes.png ¼Â½¬

¾å¤Î¥¹¥¯¥ê¥×¥È¤ò»î¤·¤Æ¤ß¤è.



Functions of shell: ¥·¥§¥ë¤Î´Ø¿ô

sh ·Ï¥·¥§¥ë¤Ç¤Ï¡¤¡ÖÊ£¿ô¤Î¥³¥Þ¥ó¥É¤ò¤Þ¤È¤á¤Æ̾Á°¤ò¤Ä¤±¤¿¤â¤Î¡×¤ò¼«Ê¬¤Çºî¤Ã¤Æ»È¤¨¤ë¡¥ ¤³¤ì¤Ï¥×¥í¥°¥é¥ß¥ó¥°¤ÎÀ¤³¦¤Ç¤Ï ´Ø¿ô ¤È¤è¤Ð¤ì¤ë¡¥

´Ø¿ô¤òºî¤ë¤Ë¤Ï¡¤



´Ø¿ô̾ () {
    ¥³¥Þ¥ó¥É¡Ä
    }

¤È¤¤¤¦¹½Ê¸¤òÍøÍѤ¹¤ë¡¥
¤Á¤Ê¤ß¤Ë¡¤{ ¤«¤é } ¤Þ¤Ç¤Î´Ö¤Ç ´Ø¿ô¤ËÂФ¹¤ë n ÈÖÌܤΰú¿ô¤ò $n ¤È¤·¤Æ»²¾È¤Ç¤­¤ë.

¤Þ¤¿¡¤¤³¤Î´Ø¿ôÆâÉô¤À¤±¤Ç»È¤¤¤¿¤¤ÊÑ¿ô¤¬¤¢¤ë¤È¤­¤Ï¡¤ local ¤òƬÉô¤Ë¤Ä¤±¤ÆÊÑ¿ôÀë¸À¤ò¤¹¤ì¤Ð¤è¤¤¡¥


warning.png ÁǤΠsh ¤Î alias ¤ÏÊÑ¿ô¤ò¤¦¤Þ¤¯»È¤¨¤Ê¤¤¤Î¤Ç¡¤¤½¤ÎÂåÂØʪ¤È¤·¤Æ´Ø¿ô¤¬Ìò¤ËΩ¤Ä¡¥



Gnome-Preferences.png ÍøÍÑÎã¡¥

  1. #!/bin/sh
  2.  
  3. mawaru () {
  4.   local i=1
  5.   while [ $i -le 10 ]
  6.     do
  7.     echo $i
  8.     i=`expr $i + 1`
  9.     done
  10. }
  11.  
  12. mawaru

¤È¤¤¤¦¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤Ï¤É¤¦¤¤¤¦Æ°ºî¤ò¤¹¤ë¤«¡¤¹Í¤¨¡¤¤½¤·¤ÆÆ°¤«¤·¤Æ¤ß¤è¤¦¡¥ ¤Ê¤ª¡¤while ʸ¤Î°ÕÌ£¤Èʸˡ¤Ï¤³¤Î¤¹¤°¸å¤Ç³Ø¤Ö¡¥ µ¤¤Ë¤Ê¤ë¿Í¤Ï¤½¤³¤òÆɤó¤Ç¤«¤éÌá¤Ã¤Æ¤³¤è¤¦¡¥

notes.png ¼Â½¬

Hello ¥¹¥¯¥ê¥×¥È¤ò¤µ¤é¤Ë²þ¤¤·¤Æ¼¡¤Î¤è¤¦¤Ë¤·¤è¤¦.

  1. #!/bin/sh
  2. # Greeting Script
  3. g='Hello'
  4. d=`date +%d`
  5. dm=`expr $d - 1`
  6. t=`date +%H`
  7. m=`date +%M`
  8.  
  9. d2min () {
  10. min=`echo "(($1 * 24) + $2) * 60 + $3" | bc -l`
  11. }
  12.  
  13. d2min $dm $t $m
  14. echo $g, "about $min minutes have passed this month."

¤½¤·¤Æ¡¤¤³¤Î¥¹¥¯¥ê¥×¥È¤ò¼Â¹Ô¤·¤Æ¤ß¤ë¤È¤È¤â¤Ë¡¤²¿¤¬¤É¤¦¤Ê¤Ã¤Æ¤¤¤ë¤Î¤«Íý²ò¤»¤è.



Flow control of shell: ¥·¥§¥ë¤ÎÀ©¸æ¹½Â¤

¡Ö¤â¤·¡Ä¤Ê¤é¤Ð¡×¤È¤«¡¤¡Ö¡Ä¤ò·«¤êÊÖ¤·¤Æ¡Ä¡×¤È¤¤¤¦Æ°ºî¤Ï¼¡¤Î¤è¤¦¤Ë¤¹¤ë¡¥



Conditional branch: if ¡Ä (ñ½ã)¾ò·ïʬ´ô

¾ò·ï¤Ë±þ¤¸¤Æ(Æó¤Ä¤Ë)ʬ´ô¤·¤Æ¤¤¤¯¡¥ ¶ñÂÎŪ¤Ê¹½Ê¸¤Ï°Ê²¼¤ÎÄ̤ꡥ

if␣¾ò·ï1
   then␣¥³¥Þ¥ó¥É1 ¡Ä

   elif␣¾ò·ï2
     then␣¥³¥Þ¥ó¥É2 ¡Ä
   elif␣¾ò·ï3
      then␣¥³¥Þ¥ó¥É3 ¡Ä

   (°Ê²¼, elif ¡Ä then ¡Ä ¤ò¹¥¤­¤Ê¤À¤±·«¤êÊÖ¤·)

   else␣¥³¥Þ¥ó¥ÉN ¡Ä
fi

warning.png ¾ò·ï ¤Î½ñ¤­Êý¤Ë¤Ä¤¤¤Æ¤Ï¡¤¤³¤Î¤¹¤°¸å¤Î JNorth_arrow-right-sm.png ¾ò·ï¼°¤ª¤è¤Ó¾ò·ï¼°¤Î¥Á¥§¥Ã¥¯ ¤Ç³Ø¤Ü¤¦¡¥

warning.png elif °Ê²¼¤È else °Ê²¼¤Ï¸ºß¤·¤Ê¤¯¤Æ¤âÎɤ¤¡¥



¾å¤Î¹½Ê¸¤Ç¤Îή¤ì¤Ï°Ê²¼¤ÎÄ̤ꡥ

ºÇ½é¤Ë ¾ò·ï1 ¤¬¼Â¹Ô & ¥Á¥§¥Ã¥¯¤µ¤ì¡¤
¾ò·ï1 ¤¬À®¤êΩ¤Ä(= ¼Â¹Ô¤¬À®¸ù¤¹¤ë) ¢ª ¥³¥Þ¥ó¥É1¡Ä ¤¬¼Â¹Ô¤µ¤ì¤Æ if ʸ¤Ï½ªÎ»¤¹¤ë¡¥
¾ò·ï1 ¤¬À®¤êΩ¤¿¤Ê¤¤ ¢ª ¼¡¤Î elif ¤Ø¡¥

¢ª ¼¡¤Î elif ¤ËÍ褿¾ì¹ç¡¥¾ò·ï2 ¤¬¥Á¥§¥Ã¥¯¤µ¤ì¡¤
¾ò·ï2 ¤¬À®¤êΩ¤Ä ¢ª ¥³¥Þ¥ó¥É2¡Ä ¤¬¼Â¹Ô¤µ¤ì¤Æ if ʸ¤Ï½ªÎ»¤¹¤ë¡¥
¾ò·ï2 ¤¬À®¤êΩ¤¿¤Ê¤¤ ¢ª ¼¡¤Î elif ¤Ø¡¥

(¡Ä °Ê²¼¡¤·«¤êÊÖ¤· ¡Ä)

¢ª else ¤ËÍ褿¾ì¹ç¡¥Ìµ¾ò·ï¤Ç ¥³¥Þ¥ó¥ÉN ¤¬¼Â¹Ô¤µ¤ì¤Æ if ʸ¤Ï½ªÎ»¤¹¤ë¡¥



notes.png ¼Â½¬

¼¡¤Î¤è¤¦¤ÊÆâÍƤΥ¹¥¯¥ê¥×¥È¤òºî¤ê¡¤¼Â¹Ô¤·¡¤Íý²ò¤»¤è. ¤¿¤À¤·¡¤if ¤Î¤¹¤°¸å¤Î [␣-e␣$fn␣] ¤È¤¤¤¦Éôʬ¤Ë¤Ä¤¤¤Æ¤Ï¸å½Ò¤¹¤ë¤Î¤ÇÍý²ò¤Ï¸å²ó¤·¤Ç¤è¤¤.

  1. #!/bin/sh
  2.  
  3. fn=~/.bashrc
  4.  
  5. if [ -e $fn ]
  6.   then
  7.     cat $fn
  8.   else
  9.     echo "You has no $fn."
  10. fi



Pattern match: case ¡Ä (¥Ñ¥¿¡¼¥ó¥Þ¥Ã¥Á)¾ò·ïʬ´ô

¤¢¤ë¡Öʸ»úÎó¡×¤¬ÍÑ°Õ¤·¤¿¥Ñ¥¿¡¼¥ó¤È¥Þ¥Ã¥Á¤¹¤ë¤«¤É¤¦¤«¤Çʬ´ô¤¹¤ë¡¥ ñ½ã¤ÊÎóµó¤Î¾ì¹çʬ¤±¤ËÊØÍø¡¥ ¥Ñ¥¿¡¼¥ó¤Ï "¦" ¤Ç¶èÀڤäÆÊÂÎóɽµ­(or ¤ò°ÕÌ£¤¹¤ë)¤¹¤ë¤³¤È¤â¤Ç¤­¤ë¡¥

¶ñÂÎŪ¤Ê¹½¤Ïʸ°Ê²¼¤ÎÄ̤ꡥ

case␣ʸ»úÎó␣in
    ¥Ñ¥¿¡¼¥ó1)␣¥³¥Þ¥ó¥É1¡Ä ;;
    ¥Ñ¥¿¡¼¥ó2)␣¥³¥Þ¥ó¥É2¡Ä ;;

( °Ê²¼, ¥Ñ¥¿¡¼¥ók)␣¥³¥Þ¥ó¥Ék¡Ä;; ¤ò¹¥¤­¤Ê¤À¤±·«¤êÊÖ¤· )

    *)␣¥³¥Þ¥ó¥ÉN¡Ä
esac



warning.png *) ¤Ï¸ºß¤·¤Ê¤¯¤Æ¤âÎɤ¤¡¥



ή¤ì¤Ï°Ê²¼¤ÎÄ̤ꡥ



ºÇ½é¤Ë ʸ»úÎó ¤òɾ²Á¤·¤Æ¡¤
ʸ»úÎ󤬥ѥ¿¡¼¥ó1 ¤È¥Þ¥Ã¥Á¤¹¤ë ¢ª ¥³¥Þ¥ó¥É1¡Ä ¤¬¼Â¹Ô¤µ¤ì¤Æ case ʸ¤Ï½ªÎ»¤¹¤ë¡¥
¥Þ¥Ã¥Á¤·¤Ê¤¤ ¢ª ¼¡¤Î¥Ñ¥¿¡¼¥ó¤È¥Þ¥Ã¥Á¤¹¤ë¤«(°Ê²¼·«¤êÊÖ¤·)

¢ª * ) ¤ËÍ褿¾ì¹ç¡¥Ìµ¾ò·ï¤Ç ¥³¥Þ¥ó¥ÉN ¤¬¼Â¹Ô¤µ¤ì¤Æ case ʸ¤Ï½ªÎ»¤¹¤ë¡¥



notes.png ¼Â½¬



¼¡¤Î¤è¤¦¤ÊÆâÍƤΥ¹¥¯¥ê¥×¥È¤òºî¤ê¡¤¼Â¹Ô¤·¡¤Íý²ò¤»¤è.

  1. #!/bin/sh
  2.  
  3. echo -n "Please input file name: "
  4. read fn
  5.  
  6. case $fn in
  7.   *.txt )
  8.     echo "$fn is text file.";;
  9.   *.c )
  10.     echo "$fn is C program file.";;
  11.   * )
  12.     echo "Hey, what is $fn ? You know it?";;
  13. esac



for ¡Ä ¤¢¤Æ¤Ï¤Þ¤ëÊÑ¿ô¤Î·«¤êÊÖ¤·

¶ñÂÎŪ¤Ê¹½Ê¸¤ÈÆ°ºî¤Îή¤ì¤Ï°Ê²¼¤ÎÄ̤ꡥ



for␣ÊÑ¿ô␣in␣¥Ñ¥¿¡¼¥óor¥ê¥¹¥È
do
    ¥³¥Þ¥ó¥É¡Ä
done



¤Þ¤º¡¤¥Ñ¥¿¡¼¥óor¥ê¥¹¥È¤òŸ³«¤·¤Æ¡¤¥ê¥¹¥È¤òÀ¸À®¤¹¤ë¡¥
¤½¤Î¥ê¥¹¥È¤ÎÍ×ÁǤò½çÈÖ¤Ë ÊÑ¿ô ¤ËÂåÆþ¤·¤Æ¡¤ ¤½¤Î¤¿¤Ó¤Ë¥³¥Þ¥ó¥É¡Ä ¤ò¼Â¹Ô¤¹¤ë¡¥



notes.png ¼Â½¬



¼¡¤Î¤è¤¦¤ÊÆâÍƤΥ¹¥¯¥ê¥×¥È¤òºî¤ê¡¤¼Â¹Ô¤·¡¤Íý²ò¤»¤è.

  1. #!/bin/sh
  2.  
  3. for x in 0 1 2 3 4 5 6 7 8 9 10
  4. do
  5.   v=`echo "$x * 0.31416" | bc -l`
  6.   echo "sin($v) = " `echo "s($v)" | bc -l`.
  7. done



Loop: while, until ¡Ä ¾ò·ï¥Á¥§¥Ã¥¯¤Ä¤­¤Ç¤Î·«¤êÊÖ¤·¡¥

¶ñÂÎŪ¤Ê¹½Ê¸¤ÈÆ°ºî¤Îή¤ì¤Ï°Ê²¼¤ÎÄ̤ꡥ



while␣¾ò·ï
do
    ¥³¥Þ¥ó¥É¡Ä
done



warning.png until ¤Î¹½Ê¸¤âƱ¤¸¡¥



¤Þ¤º¡¤¾ò·ï¤¬À®¤êΩ¤Ä¤«¥Á¥§¥Ã¥¯¡¥
[ while ¤Î¾ì¹ç] À®¤êΩ¤Ä¤Ê¤é¤Ð¡¤¥³¥Þ¥ó¥É¡Ä ¤ò¼Â¹Ô¡¥
[ until ¤Î¾ì¹ç] À®¤êΩ¤¿¤Ê¤¤¤Ê¤é¤Ð¡¤¥³¥Þ¥ó¥É¡Ä ¤ò¼Â¹Ô¡¥

ºÆ¤Ó¡¤¾ò·ï¤¬À®¤êΩ¤Ä¤«¥Á¥§¥Ã¥¯¡¥ °Ê²¼¡¤·«¤êÊÖ¤·¡¥



notes.png ¼Â½¬



¼¡¤Î¤è¤¦¤ÊÆâÍƤΥ¹¥¯¥ê¥×¥È¤òºî¤ê¡¤¼Â¹Ô¤·¡¤Íý²ò¤»¤è. ¤¿¤À¤·¡¤while ¤Î¤¹¤°¸å¤Î [␣$x␣-le␣10␣] ¤È¤¤¤¦Éôʬ¤Ë¤Ä¤¤¤Æ¤Ï¸å½Ò¤¹¤ë¤Î¤ÇÍý²ò¤Ï¸å²ó¤·¤Ç¤è¤¤.

  1. #!/bin/sh
  2.  
  3. x=0
  4.  
  5. while [ $x -le 10 ]
  6. do
  7.   v=`echo "$x * 0.31416" | bc -l`
  8.   echo "sin($v) = " `echo "s($v)" | bc -l`.
  9.   x=`expr $x + 1`
  10. done



Break-out: break ¡Ä¥ë¡¼¥×æ½Ð¡¥

¤³¤Î¥³¥Þ¥ó¥É¤¬¼Â¹Ô¤µ¤ì¤ë¤È¡¤for¡¤while, until ¤Î¥ë¡¼¥×¤«¤éæ½Ð¤¹¤ë¡¥



Termination: exit ¡Ä ½ªÎ»¡¥

¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤Î½ªÎ»¡¥



Conditional statement: ¾ò·ï¼°¤ª¤è¤Ó¾ò·ï¼°¤Î¥Á¥§¥Ã¥¯

sh ·Ï¥·¥§¥ë¤Ç¤Ï¡¤¾ò·ï¤Ï´ðËÜŪ¤Ë

[␣¾ò·ï¼°␣]

¤È¤¤¤¦·Á¼°¤Ç½ñ¤«¤ì¤ë¡¥

warning.png [ ¤È¾ò·ï¼°¤Î´Ö¤Ë¤Ï¥¹¥Ú¡¼¥¹␣¤¬É¬Íסª

# ¾Ü¤·¤¯¸À¤¦¤È¡¤[ ¤Ï¾ò·ï¼°¤ò¥Á¥§¥Ã¥¯¤¹¤ë¡¤¤È¤¤¤¦µ¡Ç½¤ò»ý¤Ä¥³¥Þ¥ó¥É¤Ç¤¢¤ë¡¥

¾ò·ï¼°¤Ï¡¤´ðËÜŪ¤Ë¡Öñ¹à±é»»»Ò¡×¤«¡ÖÆó¹à±é»»»Ò¡×¤È¹àÌܤÎÁȤ߹ç¤ï¤»¡¥

statement for files: ¥Õ¥¡¥¤¥ë¤Ë´Ø¤¹¤ë¾ò·ï¼°

-e␣̾Á°
¤½¤Î̾Á°¤Î¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¤Ê¤é¤Ð¿¿¡¥
-d␣̾Á°
¤½¤Î̾Á°¤Î¥Ç¥£¥ì¥¯¥È¥ê¤¬Â¸ºß¤¹¤ë¤Ê¤é¤Ð¿¿¡¥
-f␣̾Á°
¤½¤Î̾Á°¤ÎÄ̾ï¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¤Ê¤é¤Ð¿¿¡¥
-r␣̾Á°
¤½¤Î̾Á°¤ÎÆɤ߹þ¤ß²Äǽ¤Ê¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¤Ê¤é¤Ð¿¿¡¥
-w␣̾Á°
¤½¤Î̾Á°¤Î½ñ¤­¹þ¤ß²Äǽ¤Ê¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¤Ê¤é¤Ð¿¿¡¥
-x␣̾Á°
¤½¤Î̾Á°¤Î¼Â¹Ô²Äǽ¤Ê¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¤Ê¤é¤Ð¿¿¡¥
-s␣̾Á°
¤½¤Î̾Á°¤Î¥µ¥¤¥º¤¬ 0 ¤è¤êÂ礭¤Ê¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¤Ê¤é¤Ð¿¿¡¥

notes.png ¼Â½¬

À©¸æ¹½Â¤ if ¤Î¤È¤³¤í¤Î¼Â½¬Îã¤Ê¤É¤ò»²¹Í¤Ë¤·¤Æ¡¤¾å¤Î¾ò·ï¤ò¤Ê¤ë¤Ù¤¯Á´Éô»î¤¹¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤Æ¤ß¤è.

statement for string: ʸ»úÎó¤Ë´Ø¤¹¤ë¾ò·ï¼°

-z␣ʸ»úÎó
ʸ»úÎó¤ÎŤµ¤¬¥¼¥í¤Ê¤é¤Ð¿¿¡¥
-n␣ʸ»úÎó
ʸ»úÎó¤ÎŤµ¤¬¥¼¥í¤Ç¤Ê¤±¤ì¤Ð¿¿¡¥
ʸ»úÎó1␣==␣ʸ»úÎó2
ʸ»úÎó¤¬Åù¤·¤±¤ì¤Ð¿¿(¸«¤¨¤Ë¤¯¤¤¤¬¡¤¡Ö=¡×¤¬Æó¤Ä¤Ä¤Ê¤¬¤Ã¤Æ¤¤¤ë)¡¥
ʸ»úÎó1␣!=␣ʸ»úÎó2
ʸ»úÎ󤬰ۤʤì¤Ð¿¿¡¥

notes.png ¼Â½¬

À©¸æ¹½Â¤ if ¤Î¤È¤³¤í¤Î¼Â½¬Îã¤Ê¤É¤ò»²¹Í¤Ë¤·¤Æ¡¤¾å¤Î¾ò·ï¤ò¤Ê¤ë¤Ù¤¯Á´Éô»î¤¹¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤Æ¤ß¤è.

statement for number: ¿ôÃͤ˴ؤ¹¤ë¾ò·ï¼°

¿ôÃÍ1␣-eq␣¿ôÃÍ2
¿ôÃͤ¬Åù¤·¤±¤ì¤Ð¿¿¡¥
¿ôÃÍ1␣-ne␣¿ôÃÍ2
¿ôÃͤ¬°Û¤Ê¤ì¤Ð¿¿¡¥
¿ôÃÍ1␣-gt␣¿ôÃÍ2
¿ôÃÍ1 > ¿ôÃÍ2 ¤Ê¤é¤Ð¿¿¡¥
¿ôÃÍ1␣-ge␣¿ôÃÍ2
¿ôÃÍ1 ¡æ ¿ôÃÍ2 ¤Ê¤é¤Ð¿¿¡¥
¿ôÃÍ1␣-lt␣¿ôÃÍ2
¿ôÃÍ1 < ¿ôÃÍ2 ¤Ê¤é¤Ð¿¿¡¥
¿ôÃÍ1␣-le␣¿ôÃÍ2
¿ôÃÍ1 ¡å ¿ôÃÍ2 ¤Ê¤é¤Ð¿¿¡¥

warning.png ¾ò·ï¼°¤ÎȽÄê¤Ë¤ÏÀ°¿ô¤·¤«»È¤¨¤Ê¤¤¤¾¡ª

notes.png ¼Â½¬

À©¸æ¹½Â¤ if ¤Î¤È¤³¤í¤Î¼Â½¬Îã¤Ê¤É¤ò»²¹Í¤Ë¤·¤Æ¡¤¾å¤Î¾ò·ï¤ò¤Ê¤ë¤Ù¤¯Á´Éô»î¤¹¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤Æ¤ß¤è.

other statement: ¤½¤Î¾ ¾ò·ï¼°

!¾ò·ï¼°
NOT¤òɽ¤¹. ¾ò·ï¼°¤¬À®¤êΩ¤¿¤Ê¤±¤ì¤Ð¿¿¡¥
¾ò·ï¼°1␣-a␣¾ò·ï¼°2
AND¤òɽ¤¹. ξÊý¤Î¾ò·ï¼°¤¬À®¤êΩ¤Æ¤Ð¿¿¡¥
¾ò·ï¼°1␣-o␣¾ò·ï¼°2
OR¤òɽ¤¹. ¤É¤Á¤é¤«¤Î¾ò·ï¼°¤¬À®¤êΩ¤Æ¤Ð¿¿¡¥
( ¾ò·ï¼° )
¾ò·ï¼°¤ò¥°¥ë¡¼¥×²½¤¹¤ë¡¥ Ê£»¨¤Ê¾ò·ï¼°¤ò½ñ¤¯¤È¤­¤Ë¤Ï¡¤ °Õ¿Þ¤È°Û¤Ê¤ë·ë²Ì¤Ë¤Ê¤é¤Ê¤¤¤¿¤á¤Ë¤âÀѶËŪ¤Ë»È¤¦¤Ù¤·¡¥

notes.png ¼Â½¬

À©¸æ¹½Â¤ if ¤Î¤È¤³¤í¤Î¼Â½¬Îã¤Ê¤É¤ò»²¹Í¤Ë¤·¤Æ¡¤¾å¤Î¾ò·ï¤ò¤Ê¤ë¤Ù¤¯Á´Éô»î¤¹¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤Æ¤ß¤è.



Report: ¥ì¥Ý¡¼¥È

°Ê²¼¤Î²ÝÂê¤Ë¤Ä¤¤¤Æǽ¤¦¸Â¤ê¸­ÌÀ¤ÊÄ´ºº¤È¹Í»¡¤ò¹Ô¤¤¡¤
AppliedMath7-Report-07
¤È¤¤¤¦Âê̾¤ò¤Ä¤±¤Æ e-mail ¤Ë¤Æ¶µ´±°¸¤Ë¥ì¥Ý¡¼¥È¤È¤·¤ÆÄó½Ð¤»¤è. ¤Ê¤ª¡¤¥ì¥Ý¡¼¥È¤ò e-mail ¤ÎÂå¤ï¤ê¤Ë TeX ¤ÇºîÀ®¤·¤¿½ñÌ̤ˤÆÄó½Ð¤·¤Æ¤â¤è¤¤.

Exercises: ²ÝÂê

  1. °ú¿ô1 ¤Ë¡Ö¶â³Û¡×¤ò¡¤°ú¿ô2 ¤Ë¡ÖÆü¿ô¡×¤òÆþ¤ì¤ë¤È¡¤ ¤½¤Î¶â³Û¤Ç¤½¤ÎÆü¿ô¤À¤±¤ª¶â¤ò¼Ú¤ê¤¿¤éºÇ½ªÅª¤Ë¤¤¤¯¤é¤Ë¤Ê¤ë¤«¤ò·×»»¤¹¤ë¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤òºîÀ®¤»¤è¡¥ ¤¿¤À¤·¡¤¶âÍø¤Ï 10Æü¤Ç 1³ä (Ê£Íø)¤È¤¹¤ë¡¥
    warning.png ¤¿¤À¤·¡¤ read ¥³¥Þ¥ó¥É¤Ê¤É¤ò»È¤ï¤º¡¤¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤Î°ú¿ô¤ò¤­¤Á¤ó¤È½èÍý¤¹¤ë¤³¤È¡¥

  2. ¥Õ¥¡¥¤¥ë¤ò¾Ãµî¤¹¤ë¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤òºîÀ®¤»¤è¡¥ ¤¿¤À¤·¡¤¼¡¤Îµ¡Ç½¤ò»ý¤Ã¤Æ¤¤¤ë¤è¤¦¤Ë¤»¤è¡¥
    1. ¥Õ¥¡¥¤¥ë¤Î¥Ð¥Ã¥¯¥¢¥Ã¥×¥Õ¥¡¥¤¥ë¤¬¤¢¤ë¤«¤É¤¦¤«Ä´¤Ù¤Æ¡¤
      • ̵¤¤ ¡Ä ºîÀ®¤¹¤ë¡¥
      • ¤½¤Î¿ô¤¬3¤Ä°Ê²¼ ¡Ä ¿·¤¿¤Ë¥Ð¥Ã¥¯¥¢¥Ã¥×¥Õ¥¡¥¤¥ë¤òºîÀ®¤¹¤ë¡¥
      • ¤½¤Î¿ô¤¬3¤Ä¤è¤ê¿¤¤ ¡Ä °ìÈָŤ¤¥Ð¥Ã¥¯¥¢¥Ã¥×¥Õ¥¡¥¤¥ë¤ò¾Ãµî¤·¤Æ¤«¤é¡¤ ¿·¤¿¤Ë¥Ð¥Ã¥¯¥¢¥Ã¥×¥Õ¥¡¥¤¥ë¤òºîÀ®¤¹¤ë¡¥
    2. °Ê¾å¤Îºî¶È¤ò¹Ô¤Ã¤Æ¤«¤é¡¤¥Õ¥¡¥¤¥ë¤ò¾Ãµî¤¹¤ë¡¥

  3. ¤³¤ì¤Þ¤Ç¤Î¼ø¶È²ÝÂê¤Ç¡¤¥·¥§¥ë¥¹¥¯¥ê¥×¥È¤òÍøÍѤ·¤Æ²ò·è¤Ç¤­¤ë²ÝÂ꤬¤¢¤ì¤Ð¤½¤ì¤ò¹Ô¤¨¡¥



about Icons, ClipArts

For details, see JNorth_arrow-right-sm.png this.