I have the below script which looks for the file in the current directory and evaluates to true if the file exists in the directory and evaluates to false if it does not
#!/bin/bash
printf "\n Please enter a file name "
read num3
if [ -f $num3 ]
then
printf "It is valid script "
else
printf "Invalid file name "
fi
How can i check for the presence of the files in some other directory rather than the present directory in which the script is written ?
Try this
#!/bin/bash
printf "\n Please enter a file name "
read num3
printf "\n Please enter the path to check "
read path2check
if find $path2check -name $num3 -print -quit |
grep -q '^'; then
echo "the file exists!"
else
echo "the file does not exist!"
fi
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments