if 判断命令的返回状态 [ ] 是一个命令
如下测试代码:
if echo "weihongrao"; then
echo "this is for my name"
fi
输出为:
[leo@hadoop ~]$ ./condition.sh
weihongrao
this is for my name
测试:
[leo@hadoop ~]$ cat condition.sh
#!/bin/sh
echo "this is for condition test"
if echo "weihongrao"; then
echo "this is for my name"
fi
if test -z "$1"
then
echo "ooooooo"
fi
file=/etc/passwd
if [[ -e $file ]]
then
echo "file exits"
fi
#key : there are spaces beside any symbol show in below
if [[ 5 > 3 && 3 > 2 ]]
then
echo '5 3 2'
fi
echo 'test (())'
a=1
b=2
c=3
d=$((a+1,b+1,c++))
echo $a,$b,$c,$d
如下测试代码:
if echo "weihongrao"; then
echo "this is for my name"
fi
输出为:
[leo@hadoop ~]$ ./condition.sh
weihongrao
this is for my name
测试:
[leo@hadoop ~]$ cat condition.sh
#!/bin/sh
echo "this is for condition test"
if echo "weihongrao"; then
echo "this is for my name"
fi
if test -z "$1"
then
echo "ooooooo"
fi
file=/etc/passwd
if [[ -e $file ]]
then
echo "file exits"
fi
#key : there are spaces beside any symbol show in below
if [[ 5 > 3 && 3 > 2 ]]
then
echo '5 3 2'
fi
echo 'test (())'
a=1
b=2
c=3
d=$((a+1,b+1,c++))
echo $a,$b,$c,$d