码迷,mamicode.com
首页 > 系统相关 > 详细

【linux命令】test

时间:2017-12-05 13:25:17      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:命令   col   条件   linu   有一个   []   表达   pre   span   

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

 

【linux命令】test

标签:命令   col   条件   linu   有一个   []   表达   pre   span   

原文地址:http://www.cnblogs.com/bxbyy/p/7985988.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!