I am new to Linux and I have an assignment which requires writing a shell script that prints all the names of both files and subdirectories of a directory (given as parameter) and this should also print the number of files with the same name for every file from this directory.
My problem is that I was able to print the names of all files and directories and also to do the second part of the task, but I can't bring them together, which means that my output has two different parts:
/some/path
a1
a2
a3
a1 1
a2 1
#a1, a2 files and a3 directory
And it should look like this:
a1 1
a2 1
a3
This is the code that I used writing my shell script:
#the first part that prints all the names from the directory
mydir=$1
cd $mydir
ls -l $mydir | awk '{print $9}'
#the second part that prints the number of files with the same name for every file
file=$(find $mydir -type f -printf '%f\n' | sort | uniq -c)
echo $file