First, I am newer than new, I'm sorry this is so long, but the forum rules ask for details. Also sorry this is printing out weird.Here is what I am trying to do: I am stuck on part (B) The script you create must use only relative paths for all paths in  the code. You must assume that the script is being run from the ~  directory. (A) Create a shell script that loops through all items in a directory  given by the user using the read builtin. The script must validate  the input and use a loop to only allow the script to proceed after the  validation is complete. It must validate that the directory given is a  directory.(B) The script, while iterating over the items in the directory,  should test the items to see if they are directories or files. (B.1) If they are directories then the script needs to loop over the directory and count the number of items inside of the directory (not  recursively). The script needs to output both the name of the  directory and the number of files (and folders) inside of it to the  same line of a file named ~/sorter/directory_listing.txt. (B.2) If they are files they need to be examined for size using du with human readable output. Your script will have to write the size  followed by a space then the file name to a new line of the file  ~/sorter/files_and_sizes.txt.(C) After the loop finishes the files_and_sizes.txt file needs to be  sorted human readable then output to a file ~/sorter/files_sorted.txt  The directory_listing.txt file needs to be sorted reverse by the  number of items in the directory and output to a file named  ~/sorter/dir_reverse.txtMy attempt:read -p Please enter a directory  chosen_dirwhile [[ ! -d $chosen_dir ]]do echo Please enter a valid directory && read chosen_dirdonefor i in $chosen_dir/*;    do        counter=$((counter+1))        if [ -d $chosen_dir ]; then            ls $chosen_dir | wc -l > sorter/directory_listing.txt        else            if [ -f $chosen_dir ]; then                du -sh $chosen_dir/* > sorter/files_and_sizes.txt        fi    doneRESULT:blahblah@vm1:~$ ./taratest.shPlease enter a directory testsort./taratest.sh: line 26: syntax error near unexpected token `done'./taratest.sh: line 26: `    done'When I remove the done I get this .NEW RESULT:blahblah@vm1:~$ ./taratest.shPlease enter a directory testsort./taratest.sh: line 27: syntax error: unexpected end of fileTHEN: I searched on here forwhile iterating over the directory, test to see if the items are files or directories in bashand changed to THIS:first part of script, thenfor i in $chosen_dir/*do    [ -f $chosen_dir ] && echo is File    [ -d $chosen_dir ] && echo is DirectorydoneI KNOW THE OUTPUT IS NOT WHAT'S IN THE DIRECTIONS, I AM ECHOING JUST FOR TEST PURPOSESRESULTS:Please enter a directory testsortis Directoryis Directoryis Directoryis Directory2 are files & 2 are dirs., so why is it saying 4 dirsblahblah@vm1:~$ ls -lh testsorttotal 8.0Kdrwxrwxrwx 2 blahblah student 68 Jun  4 17:41 dir1drwxrwxrwx 2 blahblah student 68 Jun  4 17:41 dir2-rwxrwxrwx 1 blahblah student  0 Jun  4 17:41 file1.txt-rwxrwxrwx 1 blahblah student  0 Jun  4 17:41 file2.txtAny guidance on solutions is greatly appreciated.
while iterating over the directory, test to see if the items are files or directories
shell script