Tuesday, 11 June 2013

Shell Script to accept a file name and check whether the file name exist or not in current directory .

Code:
echo -n "Enter the Filename : "
read fname
if [ -f $fname ]
then
        echo "File exists in the current directory. "
else
        echo "File with this name does not exist in the current directory."
fi


Output:
[ty2011330@localhost ~]$ sh j03.sh
Enter the Filename : file5
File exists in the current directory.
[ty2011330@localhost ~]$ sh j03.sh
Enter the Filename : file12
File with this name doesnot exist in the current directory.

No comments:

Post a Comment