第十周day4.png
1、计算:
[root@m01 scripts]# cat jisuan.sh
#!/bin/bash
a=10
b=20
x=$a
y=$b
if [ $# -ne 2 ];then
echo "Usage: sh $0 num1 num2"
exit
fi
awk -vn1=$x -vn2=$y 'BEGIN {print n1/n2}'
awk -vn1=$x -vn2=$y 'BEGIN {print n1*n2}'
awk -vn1=$x -vn2=$y 'BEGIN {print n1+n2}'
awk -vn1=$x -vn2=$y 'BEGIN {print n1-n2}'
2、$数字的举例:
[root@m01 scripts]# cat ceshi1.sh
#!/bin/bash
echo $1 $0 $2 $3
[root@m01 scripts]# sh ceshi1.sh ni shi shui
ni ceshi1.sh shi shui
3、简单的判断举例:
[root@m01 scripts]# cat else.sh
#!/bin/bash
a=10
b=20
x=$a
y=$b
if [ $x -gt $y ];then
echo "我是lnb"
else
echo "好难啊!!!"
exit
fi
4、shell判断语法基础:
[root@m01 scripts]# cat cron.sh
#!/bin/bash
x=`ps -ef |grep crond|wc -l`
if [ $x -eq 2 ];then
echo "正在运行..."
elif [ $x -lt 2 ];then
echo "无法运行..."
else
echo "运行..."
fi
5、shell循环语法:
[root@m01 scripts]# cat xunhuan.sh
#!/bin/bash
for x in {1..7}
do
echo week$x 带思远去找 girl$x 大宝剑
done
网友评论