I have to delete list of directories. The list is being read from a text file. The absolute path of the directory might contain spaces as well. Here is what I am doing...
while read line # Each line is absolute path which might contain spaces
do
var1=\"${line}\"
if [ -d $var1 ]
then
rm -rf $var1
rc=$?
if [ $rc -ne 0 ]
then
echo "Remove failed for directory : $var1"
fi
else
echo "Invalid input directory : $var1"
fi
done < ${LIST}
This is not working. I also tried to execute the below code from the command line
line=/home/cg/root/3056488/test
var1=\"${line}\"
echo ${var1} # prints "/home/cg/root/3056488/test"
if [ -d ${var1} ]; then echo "success"; else echo "failure"; fi
But it is failing. How do I check if a file or directory (with spaces) exists in KSH?