簡單shell指令碼 判斷成績等級

2021-09-25 17:32:22 字數 1342 閱讀 4691

[root@server ~]# vim test.sh

#!/bin/bash

echo "please enter a number"

read num

if [ -z $num ] #判斷是否輸入了數字

then

echo "you enter nothing,please enter a number"

read num

else

if [ $num -lt 0 -o $num -gt 100 ] #判斷資料是否合法

echo "the number is invalid,please enter a number"

read num

else

if [ $num -ge 90 ] #大於等於90,成績等級為a

then

echo "the grade is a"

else

if [ $num -ge 80 ] #大於等於80,成績等級為b

then

echo "the grade is b"

else

if [ $num -ge 70 ] #大於等於70,等級等級為c

then

echo "the grade is c"

else

if [ $num -ge 60 ] #大於等於60,成績等級為d

then

echo "the grade is d"

else

echo "the grade is e" #小於60,成績等級為e

fifi

fifi

fifi————————————————————

以上為指令碼內容

[root@server ~]# chmod u+x test.sh #給指令碼可執行許可權

執行指令碼結果:

[root@server ~]# ./test.sh

please enter a number

45the grade is e

[root@server ~]# ./test.sh

please enter a number

77the grade is c

[root@server ~]# ./test.sh

please enter a number

89the grade is b

[root@server ~]# ./test.sh

please enter a number

90the grade is a

Ruby中寫乙個判斷成績分類的指令碼

需求為 從鍵盤輸入分數,以此來判斷,0 59為不及格,列印 您沒有及格,請下次努力 60 79為及格,列印 您的成績及格,請更加努力!80 100為成績良,列印 您的成績為優秀,請再接再厲 如果輸入為0 100以外的分數,請列印 您的成績為優秀,請再接再厲 如果採用ruby方式,比較精簡,如下所示 ...

判斷成績是否合格 c語言 選擇

問題描述 輸入一行字元,統計其中英文本母 空格 數字和其他字元的個數。輸入形式 輸入一行字元。輸出形式 輸出各類字串的個數。樣例輸入1 下劃線部分為鍵盤輸入,其餘部分為程式輸出 programming is fun 樣例輸出 letter 16,blank 2,digit 0,other 1 樣例輸...

shell指令碼判斷

1.test測試命令 test命令用於檢查某個條件是否成立,它可以進行數值 字元和檔案三個方面的測試,其測試符和相應的功能分別如下 1 數值測試 eq 等於則為真 ne 不等於則為真 gt 大於則為真 ge 大於等於則為真 lt 小於則為真 le 小於等於則為真 2 字串測試 等於則為真 不相等則為...