shell中判断文件目录是否存在
1、新建test.sh文件
touch test.sh
2、打开test.sh文件
vi test.sh
3、写入
#按一下“i”键
4、完整代码:
file_name=/data/datasend/D
if [ -d "$file_name" ];
then
echo "The file $file_name is exists!"
else
echo "The file $file_name is not exists!"
fi
5、保存退出
(1)按esc
(2)写入
:wq!
注意:需要注意的是 if 后面的括号里面 -d前面和后面都需要空格!
6、给test.sh赋予执行权限
chmodu+x test.sh
7、执行
sh test.sh 或者 ./test.sh