Example about Linux Shell </P> <p> #! /Bin/bash <br/> echo "Hello world! "<Br/> echo" Hello $ LOGNAME, it's nice talking to you "<br/> echo" U present working on a machine is 'uname-N' "<br/> echo" U Present working directory is $ (PWD) "<br/> echo" Bye for now $ LOGNAME. the time is $ (date + % T) "</P> <p >#================================ =============< br/> name = "tiger" <br/> export name </P> <p >#==== =======================================================< br /> DESC = $ (awk-F: '{print $2}' database.txt) <Br/> echo $ DESC </P> <p >#======================== ============================< br/> exec date # Replace the current shell, create a new shell and execute date <br/>#============================== ================< br/> echo-e "who are u? "<Br/> read answer <br/> echo" Hello $ answer, welcome! "</P> <p >#================================ ================< br/> If [$ LOGNAME! = Root] <br/> then <br/> echo "must have root privileges to run this program" <br/> Exit 1 <br/> fi <br/> CAT <warning: all jobs in the printer ques will be removed. <br/> Please turn of the printer now. press return when you are read to contine. otherwise press control C. <br/> EOF <br/> read junk # Just to wait for user response <br/> echo <br/>/etc/rc. d/init. d/lpd stop <br/> echo-e "please turn the printe R on now. "<br/> echo" Presss return to continue "<br/> read junk <br/> echo <br/>/etc/rc. d/init. d/lpd start <br/>#============================== =============< br/> WC </etc/passwd <br/> CAT/etc/passwd | WC <br/> # = ========================================================== = <br/> determine whether the condition is true <br/> character judgment: <br/> [string1 = string2] string1 equals string2 <br/> [String = string2] string1 equals string2 <br/> [String! = String2] string1 is not equal to string2 <br/> [String] string is not empty <br/> [-Z string] string length is 0 <br/> [-N string] string Length is n <br/> [-l string] String Length </P> <p> integer judgment: <br/> [int1-EQ int2] int1 is not equal to int2 <br/> [int1-ne int2] int1 is not equal to int2 <br/> [int1-GT int2] int1 is greater int2 <br/> [int1-ge int2] int1 greater than or equal to int2 <br/> [int1-lt int2] int1 less than int2 <br/> [int1-Le int2] int1 less equal to int2 </P> <p> logical judgment <br/> [[pattern1 & pattern2] P1 and P2 are true <br/> [[Pattern1 | pattern2] p1 or P2 is true <br/> [[! Pattern] P does not match </P> <p>-B Specific block file <br/>-C specific character file <br/>-d directory exists <br/>- E file <br/>-f Non-directory normal file <br/>-G file exists and belongs to a specific GID <br/>-G sets set-group-ID <br/>-K Position Setting <br/>-l file is a symbolic link <br/>-P file is a pipeline <br/>-o file exists and A valid uid <br/>-r file readable <br/>-s file is a socket <br/>-s file size is non-zero <br/>-T FD opened on the terminal <br/>-u set-user-id <br/>-W file writeable <br/>-X file executable </P> <p> #! /Bin/bash <br/> file =. /test </P> <p> If [-d $ file] <br/> then <br/> echo "$ file is a directory" <br/> Elif [- F $ file] <br/> then <br/> If [-r $ file-a-W $ file-a-x $ file] <br/> then <br/> echo "you have read, write, and execte <br/> permission on $ file "<br/> fi <br/> else <br/> echo" $ file is neither afile nor a directory. "<br/> fi </P> <p >#========================== ==========================< br/> NULL command, use. Is a built-in command that does nothing. </P> <p >#==================================== ===========< br/> case command: <br/> case variable in <br/> value1) <br/> command (s) <br/>; <br/> value2) <br/> command (s) <br/>; <br/> *) <br/> command (s) <br/> ;; <br/> esac </P> <p> #! /Bin/bash <br/> echo-n "choose a foreground color for your xterm window: "<br/> Read color <br/> case" $ color "in <br/> [BB] l ??) <Br/> xterm-FG blue-FN terminal & <br/>; <br/> [Gg] Ree *) <br/> xterm-FG darkgreen-FN terminal & <br/>;< br/> Red | orange) <br/> xterm-FG "$ color"-FN terminal & <br/>;< br/> *) <br/> xtern-FN terminal <br/> ;; <br/> esac </P> <p> echo "out of case cammnad" <br/> #================ ==========================================< br/> for command: <br/> for variable in word_list <br/> DO <br/> command (s) <br/> done </P> <p> #! /Bin/bash <br/> for PAL in Tom Dick Harry Joe <br/> DO <br/> echo "hgi $ pal" <br/> done <br/> echo "Out of loop" </P> <p> --------------- <br/> # Cat sayit <br/> Tom <br/> Patty <br/> Ann <br/> Jake </P> <p> #! /Bin/bash <br/> for person in $ (cat sayit) <br/> DO <br/> mail $ person <letter <br/> echo $ person was sent a letter. <br/> done <br/> echo "the letter has been sent. "</P> <p> for name in $ * <br/> DO <br/> echo $ name <br/> done <br/>#==== =======================================================< br /> while command: <br/> while command <br/> DO <br/> command (s) <br/> done <br/> #! /Bin/bash <br/> num = 0 <br/> while ($ num <10 )) <br/> DO <br/> echo-n "$ num" <br/> let num + = 1 <br/> done <br/> echo-e "after Loop exits, continue running here "</P> <p> ---------------- <br/> echo" Who was the 2nd U. s. president to be impeached? "<Br/> read answer <br/> while [[" $ answer "! = "Bill Clinton"] <br/> DO <br/> echo "wrong try again! "<Br/> read answer <br/> done <br/> echo you got it! </P> <p >#==================================== ===========< br/> util command <br/> #! /Bin/bash <br/> util who | grep Linda <br/> DO <br/> sleep 5 <br/> done <br/> talk Linda @ Dragonwings </P> <p> ----------------- <br/> CAT hour <br/>! /Bin/bash <br/> let hour = 0 <br/> until (hour> 24 )) or [$ hour-GT 24] <br/> DO <br/> case "$ Hour" in <br/> [0-9] | [0-1]) <br/> echo "good morning! "<Br/>;;< br/> 12) <br/> echo" lunch time. "<br/>; <br/> 1 [3-7] <br/> echo" siesta time. "<br/>; <br/> *) <br/> echo" good night "<br/> ;; <br/> esac <br/> let hour + = 1 <br/> done <br/> #============== ========================================< br/> Select menu <br/> #! /Bin/bash <br/> PS3 = "select a program to execute: "<br/> Select Program in 'LS-F' PWD date <br/> DO <br/> $ Program <br/> done </P> <p> ------------ <br/> 1) ls-F <br/> 2) PWD <br/> 3) date <br/> #? 1 <br/> p315.sh * <br/> #? 2 <br/>/home/luser623/shell <br/> #? 3 <br/> Thu Nov 10 22:12:26 CST 2005 <br/> #? 2 <br/>/home/luser623/shell <br/> #? 3 <br/> Thu Nov 10 22:12:29 CST 2005 </P> <p> ------------------------ <br/> #! /Bin/bash <br/> PS3 = "select choose one of the three boys: "<br/> select choice in Tom dan guy <br/> DO <br/> case $ choice in <br/> Tom) <br/> echo Tom is a cool dude! <Br/> Break <br/>; <br/> Dan | guy) <br/> echo Dan An guy are both wonderful. <br/> Break <br/>; <br/> *) <br/> echo "$ choice is not one of your choices" 1> & 2 <br/> echo "Try again. "<br/> ;; <br/> esac <br/> done </P> <p >#====================== ==================================< br/> shift command: <br/> shift [N]: shift the location parameter to the left N bits. If n is not displayed, n = 1 <br/> #! /Bin/bash <br/> set joe marry Tom Sam </P> <p> shift # Now S * only marry Tom Sam is left, joe has deleted <br/> set $ (date) # Thu Mar 16 PST 2000 <br/> shift 5 <br/> echo % * # Only 2000 <br/> Shift 2 <br/> shift: shift Count must B <=$ # error message </P> <p> ----------- <br/> #! /Bin/bash <br/> while ($ #> 0 )) <br/> DO <br/> echo $ * <br/> shift <br/> done <br/> [luser623 @ lbasee1 shell] $. /p318.sh 1 2 3 4 5 6 7 8 9 <br/> 1 2 3 4 5 6 7 8 9 <br/> 2 3 4 5 6 7 8 9 <br/> 3 4 5 6 7 8 9 <br/> 4 5 6 7 8 9 <br/> 5 6 7 8 9 <br/> 6 7 8 9 <br/> 7 8 9 <br/> 8 9 <br/> 9 <br/> % 2 <br/>