shell编程之基础知识1

1、shell脚本的基本格式

  #!bin/bash   ->看到这个就是shell脚本

  #filename:test.sh ->脚本名称

  #auto echo hello world ->此脚本实现的功能,这里指的是输出hello world

  #by authors ->作者

2、shell脚本的三种执行方法

  1) 空格./test.sh  注:这种需要设置执行权限,如:sudo chmod 777 test.sh

  2)/bin/bash test.sh

  3)sh test.sh

3、判断语句

  测试脚本有无问题:/bin/bash -n test.sh

  判断符号:

       -f 判断文件是否存在,如:if [ -f filename ]

       -d 判断目录是否存在,如:if [ -d dir ]

       -eq ->等于  -ne ->不等于  -gt ->大于   

       -gt ->大于  -lt ->小于    -le ->小于或等于

       -ge ->大于或等于  -a ->双方都成立  -z ->判断是否为空字符串

---恢复内容结束---

猜你喜欢

转载自www.cnblogs.com/hdc520/p/10197169.html