第一个shell脚本,直接上脚本
运行结果:
能运行出结果,真心不容易遇见的问题如下:
1.变量定义
2.变量初始化,=前后不能有空格
3.for循环
4.+前后要有空格
5.变量赋值,使用let
# /bin/sh
#if test $# -eq 0
#then
# echo "please input file name :"
#else
# rm -rf $1
# echo "file $1 is deleted!"
#fi
declare total=0
for((index = 0; index < 5; index++))
do
let total=$[$total + $index]
echo "current total = $total"
done
echo "at last total = $total"
运行结果:
yangjianzhou@OptiPlex-9020:~$ ./test.sh
bash: warning: setlocale: LC_ALL: cannot change locale (zh_CN.gbk)
current total = 0
current total = 1
current total = 3
current total = 6
current total = 10
at last total = 10
能运行出结果,真心不容易遇见的问题如下:
1.变量定义
2.变量初始化,=前后不能有空格
3.for循环
4.+前后要有空格
5.变量赋值,使用let