Linux program - 11.SHELL Script (Bash) - (5) Control Circle for

xiaoxiao2021-03-06  42

A few simple shell script, I believe you should have a little concept of Shell Script. Now let's start carefully study some higher SHELL Script writing. Some further descriptions, such as "$", ">", "<", ">>", "1>", "2>" symbols will be explained later. -------------------------------------------------- ----------------------------- for name [in word;] do list; done control ring. Word is a sequence word, and for expands individual words in Word and set it to the name of Name. List is a sequence of work. If [in Word;] is omitted, the Name will be set to the parameters added behind Script. -------------------------------------------------- ------------------------------ Example 1: #! / Bin / sh for i in a b C D e f; do Echo $ I DONE will display A to F. -------------------------------------------------- ------------------------------ Example 2: Another Usage, AZ #! / Bin / sh word = "a b C D e f G H i J L M N o P q r s T u v w x y z "for i in $ word; do echo $ I DONE This Script will display A to Z. -------------------------------------------------- ------------------------------ Example 3: Modify the repository name If you have a lot of .txt files want to be changed. DOC file, you don't need one one. #! / bin / sh files = `ls / txt / *. txt` for txt in $ files; do doc =` Echo $ txt | SED "s / .txt / .doc /" `mv $ txt $ doc done like this You can modify the * .txt file to * .doc file. -------------------------------------------------- ------------------------------ Example 4: Meow #! / Bin / sh # filename: meow for i; do cat $ I DONE When you enter "Meow File1 File2 ...", its role is the same as "Cat File1 File2 ...". -------------------------------------------------- ------------------------------ Example 5: Listbin #! / Bin / sh # filename: listbin for i in / bin / *; Do Echo $ I DONE When you enter "listbin", its role is the same as "LS / BIN / *".

转载请注明原文地址:https://www.9cbs.com/read-117572.html

New Post(0)