本周結(jié)合課堂內(nèi)容與之前的C語言基礎(chǔ),結(jié)合個人學(xué)習(xí)理解葛作,在自戀的潘旭同學(xué)幫助下猖凛,解決了完善腳本過程的一些問題。
判斷2個數(shù)的大小
#!/bin/sh
echo?"please?enter?two?number"
read?a
read?b
if?[?$a?-eq?$b?] ? ? ?(-eq 等于)
then?echo?"NO.1?=?NO.2"
elif?[?$a?-gt?$b?] ? ?(-gt 大于)
then?echo?"NO.1?>?NO.2"
else?echo?"NO.1?<?NO.2"
fi
依次輸出1-10
#!/bin/sh
for?num?in?1?2?3?4?5?6?7?8?9?10 ? ?(從1到10)
do
echo?"$num"
Done
求5的階乘
#!/bin/sh
a=1
for?b?in?1?2?3?4?5
do
a=$(($a*$b))
done
echo?$a
求10以內(nèi)能被3整除的數(shù)
#!/bin/sh:
for?a?in?1?2?3?4?5?6?7?8?9?10
do
if?[?$(($a%3))?-eq?0?] ?(不能使用“=” 虱岂,"=“只能在賦值中使用)
then
echo?$a
fi
done
輸入一個正整數(shù)判斷奇偶性(while)
#!/bin/sh
echo?"shu?ru?yi?ge?zheng?zheng?shu"
read?a
i=1
while?[?$a?-gt?$i?]
do
a=$(($a-2))
done
if?[?$a?-eq?0?]
then
echo?"ou"
else?echo?"ji"
fi