1)![](https://img-blog.csdnimg.cn/direct/9ee64b09270748cea99059538089e72a.png)
#!/bin/bash
read -p "输入符号和两个数字" n x y
case "$n" in
+)
echo $(($x$n$y)) ;;
-)
echo $(($x$n$y)) ;;
\*)
echo $(($x$n$y)) ;;
/)
echo $(($x$n$y)) ;;
*)
echo "重新输入" ;;
esac
运行结果
2)
#!/bin/bash
read -p "输入下载文件名" soft
read -p "是否下载y/n" new
if [ $new = y ] || [ $new = yes ] || [ $new = Y ]
then
echo "开始下载"
$(sudo apt-get install $soft)
else
echo "取消"
fi
运行结果
3)shell打印99乘法表
#!/bin/bash
i=1
while ((i<=9))
do
j=1
while ((j<=i))
do
echo -n "$j*$i=$((j*i))"
echo -n " "
((j++))
done
((i++))
echo ""
done
运行结果
4)
#!/bin/bash
read -p "层数" n
while ((i<n))
do
for ((j=0;j<(n-i)-1;j++))
do
echo -n " "
done
for ((k=0;k<(2*i)+1;k++))
do
echo -n "*"
done
echo ""
((i++))
done
运行结果
5)
#!/bin/bash
select name in $(ls)
do
case $name in
*.c)
echo "移除"
$(rm $name)
;;
*)
echo $name
;;
esac
done
运行结果