marcus-g
5/5/2017 - 9:24 PM

Different file or link checks -e entity exists, but this doesn't tell you what that entity is -f if a file exists -r file exists & is reada

Different file or link checks -e entity exists, but this doesn't tell you what that entity is -f if a file exists -r file exists & is readable -s file exists & isn't empty -d entity is a directory -L entity is a good link, if the link is broken, then it will pass this test, but fail the -e condition

From http://stackoverflow.com/questions/5767062/how-to-check-if-symlink-exists

if [ ! \( -e "${entity}" \) ]
then
     echo "%ERROR: entity ${entity} does not exist!" >&2
     exit
elif [ ! \( -f "${file}" \) ]
then
     echo "%ERROR: ${entity} is not a file!" >&2
     exit
elif [ ! \( -r "${entity}" \) ]
then
     echo "%ERROR: file ${entity} is not readable!" >&2
     exit
elif [ ! \( -s "${entity}" \) ]
then
     echo "%ERROR: file ${entity} is empty!" >&2
     exit
elif [ -d ${entity} ]; then
    echo "Directory"
    exit
elif [ -L ${entity} ]; then
  if [ -e ${entity} ];  then
    echo "Good link"
    exit
  else
    echo "Broken link"
    exit
  fi
fi