Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a bash script that prompts the user for the name of a file or directory an

ID: 3731525 • Letter: W

Question

Write a bash script that prompts the user for the name of a file or directory and then tests theinput as to whether it exists or not. If the input name exists, report (print to the console) whattype of object it is: regular file, directory, or another kind -- for example a symbolic link.Next, add the ability to input test values via the command line in lieu of reading user input viathe read command. Note: this is not "either or". Your script should handle both and actaccordingly, i.e., if the user executes your script by typing<script> /etc/passwordthe user shouldn't be prompted to enter a value.

Rewrite Project 2 so that instead of checking an individual file the user specifies the programchecks an entire directory. As the program tests each file, it should both print the results to thescreen and simultaneously to a file called “Filetypes_in_<directory name>”.The program should use a loop so that after each run, the user is prompted again for a directoryname to process, or can enter “Q” or “q” to quit.Constraints: The program must successfully detect whether the value entered is a directory --and process it -- or another type of file. If the value entered is not a directory the user should beinformed.

Explanation / Answer

#!/bin/bash
while :
do
if [ $# -eq 0 ]
then
    read -p "Enter Your Input: " PASSED
else
PASSED=$1
shift
fi
echo "${PASSED} this is your input"


if [ -d "${PASSED}" ] ; then
    echo "$PASSED is a directory";
    for i in `ls -a "${PASSED}"`
        do
        echo $i
        done
else
    if [ -f "${PASSED}" ]; then
        echo "${PASSED} is a file";
    else
        echo "${PASSED} is not valid";
        exit 1
    fi
fi
done
~    

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote