标签:roc info disk seq -bash 微信公众号 乘法 while +=
求从1加到100的和#!/bin/bash
declare -i sum=0
for ((i=1;i<=100;i++));do
let sum+=$i
done
echo "sum=$sum"
#!/bin/bash
i=1
sum=0
until [ $i -gt 100 ];do
let sum+=$i
let i++
done
echo "sum is:$sum"
#!/bin/bash
i=1
sum=0
while [ $i -le 100 ];do
let sum+=$i
let i++
done
echo "sum is:$sum"
#!/bin/bash
i=0
sum=0
for i in `seq 100` ;do
if [ $[$i%2] -eq 1 ];then
continue
fi
let sum+=$i
done
echo "sum is:$sum"
#!/bin/bash
i=0
sum=0
while [ $i -le 100 ];do
let i++
if [ $[$i%2] -eq 1 ];then
continue
fi
let sum+=$i
done
echo "sum is: $sum"
#!/bin/bash
i=0
sum=0
until [ $i -gt 100 ];do
let i++
if [ $[ $i%2 ] -eq 1 ];then
continue
fi
let sum+=$i
done
echo "sum is: $sum"
#!/bin/bash
#for i in `seq 9`;do
for ((j=1;j<=9;j++));do
for ((i=1;i<=j;i++));do
echo -ne "$i*$j=$(($i*$j))\t"
done
echo
done
#!/bin/bash
i=1
j=1
while[ $j -le 9 ];do
while [ $i -le $j ];do
echo -ne "$i*$j=$(($i*$j))\t"
let i++
done
echo
let i=1
let j++
done
#!/bin/bash
i=1
j=1
until [ $j -gt 9 ];do
until [ $i -gt $j ];do
echo -ne "$i*$j=$(($i*$j))\t"
let i++
done
echo
let i=1
let j++
done
#!/bin/bash
read -p "pls input a username: " username
while ! `who |grep "^$username" &> /dev/null`;do
sleep 10
done
echo "`date +%F-%H:%M:%S` $username logged on">>/tmp/user.log
#!/bin/bash
cat <<EOF
1) show cpu information;
2) show memory information;
3) show disk information;
4) quit
EOF
cpu_info(){
lscpu
}
mem_info(){
cat /proc/meminfo
}
disk_info(){
fdisk -l
}
quit(){
echo "quit"
exit 0
}
read -p "pls input a num: " num
if [ $num -ne 1 -a $num -ne 2 -a $num -ne 3 -a $num -ne 4 ];then
read -p "pls input a num again: " num
fi
case "$num" in
1)
cpu_info
;;
2)
mem_info
;;
3)
disk_info
;;
4)
quit
esac
欢迎各位关注我的微信公众号“没有故事的陈师傅”
标签:roc info disk seq -bash 微信公众号 乘法 while +=
原文地址:https://blog.51cto.com/12970189/2416630