#CA644, Assignment 1
#Part 1
#Example Solution
#The problem statement was a little confusing; this is how it's intended:
#1. Check to see if the file exists.
#2. If it does and is a directory, delete it and create a directory called test_3.
#3. If it does and is not a directory, delete it and create a directory called test_2.
#4. If it does not exist, create a regular file called test_1.
#Begin script.
#!/bin/bash
#Create variable test_file and assign it the string value "test_1"
test_file=test_1
#Create variable directory_to_test_A and assign it the string value "test_2"
directory_to_create_A=test_2
#Create variable directory_to_test_B and assign it the string value "test_3"
directory_to_create_B=test_3
#test is a builtin command that can be used to check if something is true or false.
#See https://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html
#The next line uses test to check if test_file exists.
if test -e "$test_file"
then
#Ok, now use test to check if test_file is a directory
    if test -d "$test_file"
    then
        echo "File is a directory. Deleting ..."
        rmdir "$test_file"
        echo "Creating directory \"$directory_to_create_B\"..."
        mkdir -p "$directory_to_create_B"        
    else
        echo "File is not a directory"
        echo "Removing existing file ..."
        rm "$test_file"
        echo "Creating directory \"$directory_to_create_A\"..."
        mkdir -p "$directory_to_create_A"
    fi
#Use test to check if test_file is a regular file.
elif test -f "$test_file";
then
    echo "File exists and is a regular file."
#If the file does not exist, then create it using the touch command.
else
    echo "File does not exist."
    echo "Creating a regular file called \"$test_file\" ..."
    touch "$test_file"
fi