I am trying to write a script which will tell if the file or directory exist or not. It will take the input " file name " from the user.
First this will put the ls -l
or ls
output to a file and then take input from user (for filename), later will use if condition to check if file exist or not. But my code is not working.
# !/bin/bash
ls > listtst.txt
read -p "type file name" a
if [ listtst.txt == $a ];
then
echo "file is present $a"
else
echo "file not present"
fi