目录
1、编写shell脚本,通过循环的形式在终端上打印出等腰梯形
2、编写一个bash脚本程序,用for循环实现将当前目录下的所有.c文件移到指定的目录下,最后在显示器上显示指定目录下的文件和目录。
3、自行编写 shell 脚本,实现从键盘读取两个浮点数,输出这两个数四则运算结果。
4、使用 shell 编写一个菜单,分别实现列出以下内容:(1)目录内容、(2)切换目录、(3)创建文件、(4)编辑文件、(5)删除文件的功能。
5、用 for 语句完成 1+1/2+1/3+1/4+….+1/n。
- #! /bin/bash
- for ((a=1;a<=9;a++))
- do
- for ((b=9;b>=$a;b--))
- do
- echo -n " "
- done
- for ((c=1;c<=$a;c++))
- do
- echo -n "*"
- done
- for ((d=2;d<=$a;d++))
- do
- echo -n "*"
- done
- for ((e=1;e<=9;e++))
- do
- echo -n "*"
- done
- echo ""
- done
- echo -n "input:"
- read dir
- for i in `ls | grep -E "*\.c"`
- do
- mv $i $dir
- done
- ls -IS $dir
- #! /bin/bash
- echo "please enter two number:"
- read -p"请输入第一个数字:" num1
- read -p"请输入第一个数字:" num2
- a=$(echo "scale=2;$num1+$num2" | bc)//scale表示精度
- b=$(echo "scale=2;$num1-$num2" | bc)
- c=$(echo "scale=2;$num1*$num2" | bc)
- d=$(echo "scale=2;$num1/$num2" | bc)
- echo "num1+num2=$a"
- echo "num1-num2=$b"
- echo "num1*num2=$c"
- echo "num1/num2=$d"
- #! /bin/bash
- While true
- do
- echo "(1)List you selected directory"
- echo "(2)Change to you selected directory"
- echo "(3)Creat a new file" echo "
- (4)Edit you selected file" echo "
- (5)Remove you selected file" echo "
- (6)Exit Menu"
- read input
- if test $input = 6
- then
- exit 0
- fi
- case $input in
- 1) ls;;
- 2) echo -n "Enter target directory:"
- read dir
- cd $dir
- ;;
- 3) echo -n "Enter a file name:"
- read file
- touch $file
- ;;
- 4) echo -n "Enter a file name:"
- read file
- vi $file
- ;;
- 5) echo -n "Enter a file name:"
- read file
- rm $file
- ;;
- *) echo "Please selected 1\2\3\4\5\6 " ;;
- esac
- done
- echo"please input the number"
- read number
- num=0.000
- sum=0.000
- for((i=1;i<=number;i++))
- do
- num=$(echo"scale=3;1.000/$i"|bc)
- sum=$(echo"scale=3;$sum+$num"|bc)
- done
- echo $sum