| ÂÛ̳ע²á| ¼ÓÈëÊÕ²Ø | ÉèΪÊ×Ò³| RSS
Google
Äúµ±Ç°µÄλÖãºÊ×Ò³ > LinuxƵµÀ > Linux¿ª·¢Çø > SHELL

Bourne Shell¼°shell±à³Ì

ʱ¼ä£º2006-06-28 22:35:53  À´Ô´£ºLinuxÁªÃËÊÕ¼¯  ×÷ÕߣºLinuxÁªÃËÊÕ¼¯
£ÈçÏÂËùʾ£º 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
     $ . .profile 6w6LinuxÁªÃË
     (cshÏà¶ÔÓÚ.ÃüÁîµÄÊÇsourceÃüÁî). 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
(7)ʹÓÃAnd/Or½á¹¹½øÐÐÓÐÌõ¼þµÄÃüÁîÖ´ÐÐ 6w6LinuxÁªÃË
<1> And , ½öµ±µÚÒ»¸öÃüÁî³É¹¦Ê±²ÅÓÐÖ´ÐкóÒ»¸öÃüÁî,ÈçͬÔÚÂß¼­Óë±í´ïʽÖÐÈç¹ûÇ°ÃæµÄ 6w6LinuxÁªÃË
     ½á¹ûÎªÕæÊ±²ÅÓбØÒª¼ÌÐøÔËË㣬·ñÔò½á¹û¿Ï¶¨Îª¼Ù¡£ 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
     ¸ñʽÈçÏ£º 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
     command1 && command2 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
     Àý£ºrm $TEMPDIR/* && echo "File successfully removed" 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         µÈ¼ÛÓÚ 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         if rm $TEMPDIR/* 6w6LinuxÁªÃË
         then 6w6LinuxÁªÃË
                echo "File successfully removed" 6w6LinuxÁªÃË
         fi 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
<2>Or, ÓëANDÏà·´£¬½öµ±Ç°Ò»¸öÃüÁîÖ´Ðгö´íʱ²ÅÖ´ÐкóÒ»ÌõÃüÁî 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
    Àý£º rm $TEMPDIR/* || echo "File not removed" 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         µÈ¼ÛÓ룺 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         if rm $TEMPDIR/* 6w6LinuxÁªÃË
         then 6w6LinuxÁªÃË
                command 6w6LinuxÁªÃË
         else 6w6LinuxÁªÃË
                echo "File not removed" 6w6LinuxÁªÃË
         fi 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
<3> »ìºÏÃüÁîÌõ¼þÖ´ÐÐ 6w6LinuxÁªÃË
     command1 && command2 && command3 6w6LinuxÁªÃË
        µ±command1, command2³É¹¦Ê±²ÅÖ´ÐÐcommand3 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
     command1 && command2 || comamnd3 6w6LinuxÁªÃË
         ½öµ±command1³É¹¦£¬command2ʧ°Üʱ²ÅÖ´ÐÐcommand3 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
     µ±È»¿ÉÒÔ¸ù¾Ý×Ô¼ºµÄÐèÒª½øÐжàÖÖÌõ¼þÃüÁîµÄ×éºÏ£¬Ôڴ˲»¶à½²Êö¡£ 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
  6w6LinuxÁªÃË
(8) ʹÓÃgetoptsÃüÁî¶ÁÈ¡unix¸ñʽѡÏî 6w6LinuxÁªÃË
    UNIX¸ñʽѡÏîÖ¸ÈçϸñʽµÄÃüÁîÐвÎÊý£º 6w6LinuxÁªÃË
    command -options parameters 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
    ʹÓøñʽ£º 6w6LinuxÁªÃË
    getopts option_string variable 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
    ¾ßÌåʹÓ÷½·¨Çë²Î¿¼getoptsµÄÔÚÏßÎĵµ(man getopts). 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
    ʾÀýÈçÏ£º 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         #newdate 6w6LinuxÁªÃË
         if [ $# -lt 1 ] 6w6LinuxÁªÃË
         then 6w6LinuxÁªÃË
             date 6w6LinuxÁªÃË
         else 6w6LinuxÁªÃË
            while getopts mdyDHMSTjJwahr OPTION 6w6LinuxÁªÃË
            do 6w6LinuxÁªÃË
               case $OPTION 6w6LinuxÁªÃË
               in 6w6LinuxÁªÃË
                  m) date '+%m ';;  # Month of Year 6w6LinuxÁªÃË
                  d) date '+%d ';;  # Day of Month 6w6LinuxÁªÃË
                  y) date '+%y ';;  # Year 6w6LinuxÁªÃË
                  D) date '+%D ';;  # MM/DD/YY 6w6LinuxÁªÃË
                  H) date '+%H ';;  # Hour 6w6LinuxÁªÃË
                  M) date '+%M ';;  # Minute 6w6LinuxÁªÃË
                  S) date '+%S ';;  # Second 6w6LinuxÁªÃË
                  T) date '+%T ';;  # HH:MM:SS 6w6LinuxÁªÃË
                  j) date '+%j ';;  # day of year 6w6LinuxÁªÃË
                  J) date '+%y%j ';;# 5 digit Julian date 6w6LinuxÁªÃË
                  w) date '+%w ';;  # Day of the Week 6w6LinuxÁªÃË
                  a) date '+%a ';;  # Day abbreviation 6w6LinuxÁªÃË
                  h) date '+%h ';;  # Month abbreviation 6w6LinuxÁªÃË
                  r) date '+%r ';;  # AM-PM time 6w6LinuxÁªÃË
                  ?) echo "Invalid option $OPTION";; 6w6LinuxÁªÃË
               esac 6w6LinuxÁªÃË
            done 6w6LinuxÁªÃË
         fi 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         $ newdate -J 6w6LinuxÁªÃË
         94031 6w6LinuxÁªÃË
         $ newdate -a -h -d 6w6LinuxÁªÃË
         Mon 6w6LinuxÁªÃË
         Jan 6w6LinuxÁªÃË
         31 6w6LinuxÁªÃË
         $ newdate -ahd 6w6LinuxÁªÃË
         Mon 6w6LinuxÁªÃË
         Jan 6w6LinuxÁªÃË
         31 6w6LinuxÁªÃË
         $ 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         ʾÀý³ÌÐò£º¸´ÖƳÌÐò 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         # Syntax: duplicate [-c integer] [-v] filename 6w6LinuxÁªÃË
         #    where integer is the number of duplicate copies 6w6LinuxÁªÃË
         #    and -v is the verbose option 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         COPIES=1 6w6LinuxÁªÃË
         VERBOSE=N 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         while getopts vc: OPTION 6w6LinuxÁªÃË
         do 6w6LinuxÁªÃË
            case $OPTION 6w6LinuxÁªÃË
            in 6w6LinuxÁªÃË
               c) COPIES=$OPTARG;; 6w6LinuxÁªÃË
               v) VERBOSE=Y;; 6w6LinuxÁªÃË
               ?) echo "Illegal Option" 6w6LinuxÁªÃË
                   exit 1;; 6w6LinuxÁªÃË
            esac 6w6LinuxÁªÃË
         done 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         if [ $OPTIND -gt $# ] 6w6LinuxÁªÃË
         then 6w6LinuxÁªÃË
            echo "No file name specified" 6w6LinuxÁªÃË
            exit 2 6w6LinuxÁªÃË
         fi 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         shift `expr $OPTIND -1` 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         FILE=$1 6w6LinuxÁªÃË
         COPY=0 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         while [ $COPIES -gt $COPY ] 6w6LinuxÁªÃË
         do 6w6LinuxÁªÃË
            COPY=`expr $COPY + 1` 6w6LinuxÁªÃË
            cp $FILE ${FILE}${COPY} 6w6LinuxÁªÃË
            if [ VERBOSE = Y ] 6w6LinuxÁªÃË
            then 6w6LinuxÁªÃË
               echo ${FILE}${COPY} 6w6LinuxÁªÃË
            fi 6w6LinuxÁªÃË
         done 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
  6w6LinuxÁªÃË
         $ duplicate -v fileA 6w6LinuxÁªÃË
         fileA1 6w6LinuxÁªÃË
         $ duplicate -c 3 -v fileB 6w6LinuxÁªÃË
         fileB1 6w6LinuxÁªÃË
         fileB2 6w6LinuxÁªÃË
         fileB3 6w6LinuxÁªÃË
  6w6LinuxÁªÃË
  6w6LinuxÁªÃË
4.
 8/12   |‹ ‹‹ 6 7 8 9 10 11 ›› ›|

À´¶¥Ò»ÏÂ
½ü»ØÊ×Ò³
·µ»ØÊ×Ò³
·¢±íÆÀÂÛ ¹²ÓÐÌõÆÀÂÛ
Óû§Ãû: ÃÜÂë:
ÑéÖ¤Âë: ÄäÃû·¢±í
Ïà¹ØÎÄÕÂ
    ÎÞÏà¹ØÐÅÏ¢
À¸Ä¿¸üÐÂ
À¸Ä¿ÈÈÃÅ