虚拟机
linux
编写一个shell脚本程序,实现从键盘读入x、y的值,然后做加法运算,最后输出结果。
#!/bin/shread -p 'Input X:' xread -p 'Input Y:' yecho 'x+y=$(($x + $y))'
利用内部变量和位置参数编写一个简单的删除程序来删除某个文件
#!/bin/shread -p 'Input delete fileName:' filerm -rf $file#!/bin/shread -p 'Input equal string:' stringif ['$string' = '']then echo 'Input string is null'else echo 'Input string lenght ${#string}'fi
编写一个shell程序用for求从2+4+6+6+…+100的和
#!/bin/bashsum=0;j=2;for ((i=2;i<=100;i+=2))do sum=$(($sum + $i))doneecho 'The result is $sum (for)'
用while求从2+4+6+6+…+100的和
sum=0;j=2;while((j<=100))do sum=$(($sum + $j)) j=$(($j + 2))doneecho 'The result is $sum (while)'
用untill求从2+4+6+6+…+100的和
sum=0;j=2;until [ $j -gt 100 ]do sum=$(($sum+$j)) j=$(($j + 2))doneecho 'The result is $sum (until)'
以上只是本人的个人见解,仅供参考
觉得有帮助的话,可以关注