shell脚本并不能作为正式的编程语言,因为它是在Linux的shell中运行的,所以称他为shell脚本. 事实上,shell脚本就是一些命令的集合. 我们不妨吧所有的操作都记录到一个文档中,然后去调用文档中的命令,这样一步操作就可以完成了 一般shell脚本都是放在/usr/local/sbin的目录下 1.shell脚本的创建和执行 #cd usr/local/sbin # vim first.sh #! /bin/bash ##this is my first shell script
重要使用的是EOF的功能,亲测和!功能一致:下面是测试代码 #!/bin/bash val=`ls`for v in ${val} do if [ ${v} == "test.db" ] then rm test.db echo "rm test.db" fidone sqlite test.db << EOFcreate table test(name char,sex char);insert into test values("yang&
shell的循环控制语句 - continue:提前结束某次循环,重新开始下一次 - break:提前结束某层循环 范例: #求100以内的奇数和 #!/bin/bash sum=0 for i in `seq 100`;do if [ $[i%2] -ne 0 ];then continue else let sum+=$i fi done echo $sum #实现100以内的奇数和 #!/bin/bash sum=0 for i in `seq 100`;do #``:命令替换 if [
写在前面:案例.常用.归类.解释说明.(By Jim) 使用函数 #!/bin/bash # testing the script function myfun { echo "This is an example of a function" } count=1 while [ $count -le 5 ] do myfun count=$[ $count +1 ] done echo "This is the end of the loop" myfun ech