判断文件或目录是否存在

判断文件或目录是否存在

#!/bin/bash
if [ $# -eq 0 ] ;then
echo "未输入任何参数,请输入参数"
echo "用法:$0 [文件名|目录名]"
fi
if [ -f $1 ];then
echo "该文件,存在"
ls -l $1
else
echo "没有该文件"
fi
if [ -d $1 ];then
 echo "该目录,存在"
 ls -ld $2
else
 echo "没有该目录"
fi
发布了221 篇原创文章 · 获赞 177 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_44799645/article/details/105480838