一 按照文件类型进行判断

Shell条件判断语句上
 
 
二 两种判断格式
test -e /root/install.log
[ -e /rout/install.log ]
第一个判断命令如果正确执行,则打印“yes”,否则打印“no”
[ -d /root ] && echo "yes" || "no"
 
三 实战
abc canyls Downloads Pictures Templates
abcd ChangeLog-2.6.0 initial-setup-ks.cfg Public test.txt
anaconda-ks.cfg Desktop linux-2.6.39.tar.bz2 sh Videos
cangls Documents Music student.txt XshellXftpPortable.zip
[[email protected] ~]# [ -e /root/test.txt ]
[[email protected] ~]# [ -e /root/test.txt2 ]
[[email protected] ~]# echo $?
1
[[email protected] ~]# [ -d /root ] && echo "yes" || "no"
yes
[[email protected] ~]# [ -e /root/test.txt ] && echo "yes" || "no"
yes
 
四 按照文件权限判断

Shell条件判断语句上
 
 
五 实战
[[email protected] ~]# [ -w /root/test.txt ] && echo "yes" || "no"
yes

相关文章: