Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Combing the basic knowledge of shell script & lt; Nine & gt;:break jumps out of the whole cycle; continue jumps out of this cycle

2025-02-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

The break command allows you to jump out of all loops (terminate the execution of all subsequent loops)

#! / bin/bash

While:

Do

Echo-n "enter a number between 1 and 5:"

Read aNum

Case $aNum in

1 | 2 | 3 | 4 | 5) echo "the number you entered is $aNum!"

*) echo "the number you entered is not between 1 and 5! game over"

Break

Esac

Done

Break instance 2

#! / bin/bash

I, 1

For day in mon tue wed thu fri

Do

Echo "Weeking $((iTunes +)): $day"

If [$I-eq 3]; then

Break

Fi

Done

Execution result

[root@zabbix shell] # sh break.sh

Weeking 1: mon

Weeking 2: tue

The continue command is similar to the break command, except that it does not jump out of all loops, just out of the current loop.

Modify the above example:

#! / bin/bash

While:

Do

Echo-n "enter a number between 1 and 5:"

Read aNum

Case $aNum in

1 | 2 | 3 | 4 | 5) echo "the number you entered is $aNum!"

*) echo "the number you entered is not between 1 and 5!"

Continue

Echo "Game over"

Esac

Done

Contibue instance 2

#! / bin/bash

I, 1

For day in mon tue wed thu fri sat sun

Do

Echo-n "Day $((iTunes +)): $day"

If [$I-eq 7-o $I-eq 8]; then

Echo "(WEEKEND)"

Continue

Fi

Echo "(weekday)"

Done

Execution result

[root@zabbix shell] # sh break.sh

Day 1: mon (weekday)

Day 2: tue (weekday)

Day 3: wed (weekday)

Day 4: thu (weekday)

Day 5: fri (weekday)

Day 6: sat (WEEKEND)

Day 7: sun (WEEKEND)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report