Thursday, April 2, 2015

Detecting file type

Program (filetype.sh)
# File type
echo -n "Enter filename : "
read fname
if [ -e $fname ]
then
if [ -f $fname ]
then
echo "Regular file"
elif [ -d $fname ]
then
echo "Directory"
else
echo "Special file"
fi
else
echo "File does not exist"
fi
Output
[vijai@localhost command]$ sh filetype.sh
Enter filename : samp.c
Regular file

No comments:

Post a Comment