my professor have gave an assignment to write a shell script to find how many files are there in the current directory using ls and wc. Additionally wants to print a message if it is empty.
i have tried referring to the man pages for help but couldn’t work.3
>Solution :
Here Using wc -l is better as it will count the lines and help with miscellaneous names:
#! /bin/bash
files=`ls | wc -l`
if [ $files == 0 ]
then
echo "Directory is empty"
else
echo "No of files = " $files
fi