Shell introduction-bash programming-process control (2)

Source: Internet
Author: User
Article title: shell introduction-bash programming-process control (2 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
F ::
While
Syntax:
While (condition)
Do
Commands
Done
For example:
#! /Bin/bash
Number = 0
While (test $ number-lt 10)
Do
Echo "$ number \ c"
Number = 'expr $ number + 1'
Done
Echo
-----------------------------------------
The result is as follows:
0123456789
G ::
Until
Syntax:
Until (condition)
Do
Commands
Done
It differs from while in that while executes a loop when the condition is true, while until executes a loop when the condition is false.
H ::
Break and continue
The two are used for loop control such as for, while, and. The break will jump to done before execution, while the continue will jump
Done before execution, while continue will jump to done for execution and continue to execute the loop.
I ::
Case
Syntax:
Case str in
Pat1) commands1 ;;
Pat2) commands2 ;;
Pat3) commands3 ;;
Esac
In addition to specifying certain strings, pat can also specify a string set, as shown below:
* Any string
? Any character
[Abc] a, B, and c
[A-n] any character from a to n
│ Multiple options
For example:
Test8.sh
-----------------------------------------------------------
#! /Bin/bash
Echo 'enter A, B, C :"
Read letter
Case $ letter in
A │ a) echo 'You entered .';;
B │ B) echo 'You entered B .;;
C │ c) echo 'You entered C ,;;
*) Echo 'not a, B, c ';;
Esac
----------------------------------------------------------------------
J ::
Function
The format is as follows:
Function-name ()
{
Commands
}
   <Br> to call this function, you can directly use the command line. <Br> <xmp> <br> test1 () <br >{< br> echo 'this is fuction 1' <br >}< br> test2 () <br >{< br> echo 'this is fuction2' <br >}< br> test2 <br> test1 <br> ---------------------------------------------------- <br> running result: <br> this is fuction2 <br> this is fuction1 <br> below are some common shell examples: <br> Example 1 renames a batch of files. <Br> \ ls *. c * sed's /\(. *\). C \(. * \)/mv & \ 1/'│ sh <br> or <br> for f in *. foo; <br> fo <br> base = 'basename $ f. foo '<br> mv $ f $ base. bar <br> done <br> Example 2: replace the uppercase file name with the name of the file. <Br> for f in *; do <br> mv $ f'echo $ f │ tr' [a-z] '] [a-z] <br> done <br>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.