If语句格式:
Eg:
- #!/bin/bash
- if [ “3” –lt “6” ]//要注意if后面有一个空格,“3”和“6”的前后各有一个空格
- then
- echo “3 is less 6”
- else
- echo “3 is more 6”
- fi//注意在结束的时候一定要有结尾的返写否则会出错
eg:
这是另外一个例子
- #!/bin/bash
- if cp a.sh a/;
- then
- echo "Successful!"
- else
- echo "'beasename $0':error could not copy the files">&2
- fi
从以下这个例子中可以看出linux对格式要求是相当严的
- #!/bin/bash
- echo -n "Please enter your name:"
- read name
- if [ -z $name ] || [ "$name" = "" ]//每个符号之间都空格,这一行一共9个空格
- then
- echo "Please enter your name!"
- elif [ "$name" = "root" ]//这一行有4个空格
- then
- echo "Hello root"
- else
- echo "Hello $name"
- fi