1. 编写shell脚本,计算1-100的和: #! /bin/bash sum=0 for i in `seq 1 100`; do sum=$[$i+$sum] done echo $sum 计算-00和 2. 编写shell脚本,要求输入一个数字,然后计算出从1到输入数字的和,要求,如果输入的数字小于1,则重新输入,直到输入正确的数字为止: #! /bin/bash n=0 " ]; do read -p "Please input a number, it must great…
一.echo命令 #1.直接显示字符串 echo "It is a test" #输出:It is a test #2.显示转义字符 echo "\"It is a test\"" #输出:"It is a test" #3.显示变量 name=Shell echo "$name It is a test" #输出:Shell is a test #4.显示换行 echo -e "OK! \n&q…
参考博客: [1]Shell脚本的条件控制和循环语句 一.条件控制语句 1.if语句 1.1语法格式: if [ expression ] then Statement(s) to be executed if expression is true fi 注意:expression 和方括号([ ])之间必须有空格,否则会有语法错误. if 语句通过关系运算符判断表达式的真假来决定执行哪个分支.Shell 有三种 if ... else 语句: if ... fi 语句 if ... else…