1.输出直角三角形
#!/bin/bash
echo "Please type your number:"
read a
for (( i=1;i<=a;i++))
do
for ((p=1;p<=i;p++))
do
echo -n " $p "
done
echo
done
echo
输出结果如图:
=================================================================
2. 输出9*9乘法表
#!/bin/bash
for (( i=1;i<10;i++))
do
for ((p=1;p<=i;p++))
do
echo -ne " ${p}x$i="`expr $i \* $p`
done
echo
done
echo
输出结果:
3. 计算器
#!/bin/bash
while true
echo "... ... ... .... .+"
echo "... ... ... .... .-"
echo "... ... ... .... .x"
echo "... ... ... .... ./"
echo "... ... ... .... .q"
echo "Please type your word: (e.g.1 + 2)"
read a b c
do
case $b in
+) echo " $a+ $c=" `expr $a + $c`;;
-) echo " $a - $c =" `expr $a - $c`;;
x) echo " $a x $c =" `expr $a \* $c`;;
/) echo " $a / $c ="`expr $a \/ $c`;;
esac
case $a in
q) break ;;
esac
done
4. 记事本
#!/bin/bash
if [ !-f /root/minda ]
then
touch /root/minda
fi
while true
echo "if you want to add a user,please type------------"
echo "if you want to del a user,please type------------"
echo "if you want to watch users,please type------------"
echo "if you want to edit users,please type------------"
echo "if you want to exit,please type------------"
read b
do
case $b in
a) echo "Please type your name:"
read name
echo "Please type your number:"
read number
echo $name $number >> /root/minda;;
d) echo "Please type which name do you want to del;"
read name
cat /root/minda | grep ^[^$name] > /root/minda;;
l) cat /root/minda;;
e) echo "Please type which name do you want to del:"
read name
cat /root/minda | grep ^[^$name] >> /root/minda
echo "Please type your new name:"
read name
echo "Please type your new number:"
read number
echo $name $number >> /root/minda;;
q) exit;;
esac
done