Usage of the Linux shell break, continue, exit, return

Source: Internet
Author: User


Break, continue, exit, return are generally used to control the direction of the loop

Start with a script description

For ((i=1;i<5;i++))

Do

If [$i-eq 3]

Then

# break

# continue

# exit

Fi

Echo $i

Done

Echo OK

Results of the output

Result of break

1

2

Ok

Results of continue

1

2

4

Ok

Result of exit

1

2


This can explain

Break N/A indicates the number of layers that jump out of the loop, and if n is omitted to jump out of the loop

Continue n-n means to return to the nth level to continue the loop, if omitting n means jumping out of the loop, ignoring the remainder of the loop, and entering the next loop of the loop

Exit N: Exit the current shell program and return to N,n can also omit

Return: returned value of function


Example: Temporarily configure multiple IP addresses for the server and can revoke all IP configurations at any time

IP address: 10.0.0.1-10.10.0.0.16, where 10.0.0.10 cannot be configured

#ifconfig eth0:1 10.10.0.1 netmask 255.255.0.0 up

A simple implementation

For ((i=1;i<=16;i++))

Do

If [$i-eq 10]

Then

Continue

Fi

Ifconfig eth0: $i 10.0.0. $i netmask 255.255.0.0 down

Done

Or

Case "$" in

Start

For ((i=1;i<=16;i++))

Do

If [$i-eq 10]

Then

Continue

Fi

Ifconfig eth0: $i 10.0.0. $i netmask 255.255.0.0 "$"

Done

;;

Stop

For ((i=1;i<=16;i++))

Do

If [$i-eq 10]

Then

Continue

Fi

Ifconfig eth0: $i 10.0.0. $i netmask 255.255.0.0 "$"

Done

;;

*)

echo "usage:$0 [Start|stop]"

Esac


This article is from the "ngames" blog, make sure to keep this source http://ngames.blog.51cto.com/3187187/1537066

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.