Script No .
Definition:
Write a shell script that takes a filename from the user and checks whether it is a
directory file or not.
• If it is a directory, then the script should display the contents of the directory.
• If it is not a directory file then script should display the message: “File is not a
directory file “
Script:
#This script accepts a filename and if it directory,
#displays the contents of the directory
clear
echo Enter the filename
read fn
if [ -d $fn ]
then
echo $fn is a directory file
echo Contents of Directory $fn
cd $fn
ls
else
echo File is not a directory file or does not exists
fi
OR
echo "Enter the file name"
read fn
if [ -d $fn ]
then
echo "Its a directory"
ls $fn
else
echo "Its not directory"
fi
OR
if [ -d $1 ]
then
ls
else
echo "File is not a directory file "
fi