> shell编程 >

shell脚本检测文件是否存在

一例shell脚本,用于检测文件是否存在,shell中-f参数检测指定文件存在与否。


例子,shell脚本 检查文件是否存在。
 

 

#!/bin/bash
#

FILE="/etc/hosts"
if [ -f $FILE ]; then
  echo "File ${FILE} exists"
else
  echo "File ${FILE} does NOT exists"
fi

 

(责任编辑:IT)