shell中的判断 if then用法

1. 判断f根目录文件是否存在

#如果文件不存在需要创建

 if [  !  -f "/creat_file" ]; then 

    mkdir -p /create_file 

fi

#如果文件存在,需要删除,

 if [  -f "/creat_file" ]; then

   rm  -rf   create_file

fi

2. 判断指定目录的某个文件是否存在

file_1 = "/etc/init.d/rc.local"

 if [  -f "$file_1" ]; then

   rm  -rf   $file_1 

   echo "$file remove"

fi

///

参数意义:  https://blog.csdn.net/qq_26620783/article/details/114582335


版权声明:本文为qq_26620783原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。