【linux命令】test

1、表达式

#!/bin/bash

# if test 表达式1 【表达式为真】
if test 1 == 1;then
 echo 'test 条件为真'
fi
# if test 表达式1 【等同于】 if [ 表达式1 ]
if [ 1 == 1 ];then
 echo '[] 条件为真'
fi
# if test ! 表达式1        【表达式为假】
if test ! 2 == 1;then
 echo 'test 条件为假'
fi
# if test 表达式1 -a 表达式2
if test 1 == 1 -a 2 == 2;then
 echo '表达式1 和 表达式2 都为真'
fi
# if test 表达式1 -o 表达式2
if test 1 == 1 -o 2 == 3;then
 echo '表达式1 或 表达式2 有一个为真'
fi

2、文件(夹)

#/bin/bash
for fileName in `ls`
do
if test -f $fileName;then
 echo $fileName '是文件'
elif test -d $fileName;then
 echo $fileName '是目录'
fi
done

 

posted @ 2017-12-05 11:18  白小白001  阅读(249)  评论(0编辑  收藏  举报