Check if file exists in ksh

ksh
mibzer picture mibzer · Feb 23, 2012 · Viewed 79.2k times · Source

I wonder why the below tiny script is now working. I created dfFile under /data directory but script does not print the expressions in if statement.

#!/bin/ksh
DATAFILE="/data/dfFile"
echo $DATAFILE
#df -h>/data/dfFile
  if [[ -e DATAFILE ]]
  then
    echo "sa"
    echo $DATAFILE
     df -h > $DATAFILE
  fi

Answer

glenn jackman picture glenn jackman · Feb 24, 2012

That should read

  if [[ -e "$DATAFILE" ]]