Linux Shell 03 Process Control statements

Source: Internet
Author: User

I. If statement format: Supports if/elif/else forms, supports nesting

1. When command execution succeeds (and exit status is 0), execute Command2

2. When the judging condition is the test command, the Command2 is executed when the result is true

if command; then   Command1
Else
Command2fiif commandthen commandfi

Two. For statement format

 for var inch List  Do     Commanddone

1. Read the list of values

A. The values in the list are separated by a space by default,

B. Include single quotes in the value to escape or use double quotation marks

C. The value contains spaces, which need to be enclosed in double quotation marks.

 for var inch I\'m come from Nanjing and I want go to "New York", I can\ ' t say Francedo    echo $
   
    var
     Done
   

2. Reading a list from a variable

list="AAA BBB CCC"list= $list"  CCC"    #字符串追加内容  for var inch List  Do     echo $var Done

3. Read the command value

 for var  in ' cat/etc/passwd 'does    echo $var Done

4. Field Separators

In the 3 example, the content is not output on a row, because space/tab/line breaks are considered field separators in the shell

In the example above, if you want content to be output by row, you need to modify the field delimiter

Ifs. old=$IFSIFS=$'\ n'forvar in ' cat/etc/passwd '  do    echo $vardoneifs= $IFS. Old

Three. While statement

Four. Do...until statements

Five. Continue and break statements

Linux Shell 03 Process Control statements

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.