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

Shell Loop statement: if

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

Share

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

[root@master1-192,168117-18 ~] # vim mkcdrom.sh

#! / bin/bash

DIR= "/ media/cdrom"

If [!-e $DIR]

Then

Mkdir-p $DIR

Fi

[root@master1-192,168117-18 ~] # vim chkhost.sh

#! / bin/bash

Ping-c 3-I 0.2-W 3 $1 & > / dev/null

If [$?-eq 0]

Then

Echo "Host $1 is on-line"

Else

Echo "Host $1 is off-line"

Fi

[root@master1-192,168,117-18] # bash chkhost.sh 192.168.1.11

Host 192.168.1.11 is on-line

Note: the-c parameter specifies the number of attempts, uses the-I parameter to define the interval between each packet, and uses the-W parameter to define the wait timeout

[root@master1-192,168117-18 ~] # vim chkscore.sh

#! / bin/bash

Read-p "Enter your score (0100):" GRADE

If [$GRADE-gt 100]

Then

Echo "$GRADE is Error"

Elif [$GRADE-ge 85] & & [$GRADE-le 100]

Then

Echo "$GRADE is Excellent"

Elif [$GRADE-ge 70] & & [$GRADE-le 84]

Then

Echo "$GRADE is Pass"

Else

Echo "$GRADE is Fail"

Fi

[root@master1-192,168117-18 ~] # bash chkscore.sh

Enter your score (0-100):

200 is Error

[root@master1-192,168117-18 ~] # bash chkscore.sh

Enter your score (0100): 93

93 is Excellent

[root@master1-192,168117-18 ~] # bash chkscore.sh

Enter your score (0-100): 80

80 is Pass

[root@master1-192,168117-18 ~] # bash chkscore.sh

Enter your score (0100): 23

23 is Fail

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