str1 = str2

str1 != str2

str1 < str2

str1 > str2

-n str1   str1为非null(长度大于0)

-z str1   str1为非null(长度为0)

 

常用操作符(为真)

-b 块设备文件

-c 字符设备文件

-d 目录

-e 存在

-f 一般文件

-g file file有设置它的setgid位

-h 符号链接

-L 符号链接

-p 管道

-r 可读

-S 套接字

-s 非空

-u file有设置它的setgid位

-w 可写

-x 可执行,若是目录,则可被查找

-O file file的所有者

-G file的组ID匹配你的ID

file1 -nt file2 file1比file2新

file1 -ot file2 file1比file2旧

 

 

#!/bin/bash

# 测试文件判断操作

file = $1

if [ -d $file ]

then

echo “$file is a directory.”

elif [ -f $file ]

then

if [ -r $file ] && [ -w $file ] && [ -x $file ]

then

echo “you have read, write and excute permission on $file.”

fi

else

echo “$file is neither a file nor a directory.”

fi

 

if [ “$1” = “-f” ]

then

elif

echo $1:unknown option >&2

exit1

fi

Leave a Reply

Your email address will not be published. Required fields are marked *