I want to create a script that will list in long form the contents of a directory. However, I want to make sure first that the user does not add input to the script command line until prompted if so I need to apply an error and exit. If it passes that test, then the script should then ensure the directory exists before attempting to list it. If it doesn't then another error out. If it exists I need to display the contents in long listing.
I'm really new at this and here is what I have so far. I'm not sure that I'm even on the right track. Any help would be appreciated.
#!/bin/bash
# File Name: dlist
# Usage: dlist prompt: [/directory/path/here]
# Synopsis: The dlist script will prompt the user to input a directory path and will
# return a long listing of the contents in that directory.
# Author: Romero
# Notify user of incoming prompt
echo -e "You will be prompted to enter the name of a directory you want to list in long form. "
# Prompt the user to input the directory to list on the same line as the input prompt
read -p "Directory to list: "
# Ensure User has not input directly into command line; if so issue std error 1 and exit
# Check to ensure directory exists before listing; if not issue std error 2 and exit
# If directory exists, list it in long form
if [ ! -d "$DIRECTORY" ]; then
echo "This directory does not exist to list!" 1>&2
exit 2
elif [ -d "$DIRECTORY" ]; then
echo ls -l "$DIRECTORY"
fi