Script - Bash

Just a Bash Scripting practice

#!/bin/bash

harun_employment() {
    touch harun_employment.txt
    touch harun_starter.txt
}

karim_employment() {
    touch karim_employment.txt
    touch karim_starter.txt
}

crespo_employment() {
    touch crespo_employment.txt
    touch crespo_starter.txt
}

delete_files() {
    for file in *
        do
            if [[ "$file" != "part1.sh" && "$file" != "part2.sh" && "$file" != "part3.sh" && "$file" != "part4.sh" ]]
            then
                rm "$file"  
                echo "File deleted : "$file""
            fi
        done
}

if [ $# -eq 0 ]; 
    then
        echo "No flags provided."
        echo "Usage: $0 [-a] [-b] [-c] [-d] [-e <value>]"
        exit 1
fi

while getopts 'abcde:h' OPTION
    do
        case "$OPTION" in
            a)
                harun_employment
            ;;
            b)
                karim_employment
            ;;
            c)
                crespo_employment
            ;;
            d)
                delete_files
            ;;
            e)
                name="$OPTARG"
                echo "[+] Checking employment files for $name..."
                employment="${name}"_employment.txt
                starter="${name}"_starter.txt

                if [ -f "$employment" ]; then
                    echo "Employment file for $name exists"
                else
                    echo "Employee $name files (Employment & Starter) do not exist"
                    if [ "$name" == "harun" ]; then
                        echo "Use flag -a to create files for "$name""
                    elif [ "$name" == "karim" ]; then
                        echo "Use flag -a to create files for "$name""
                    elif [ "$name" == "crespo" ]; then
                        echo "Use flag -c to create files for "$name""
                    else
                        echo "Please contact Admin to do process 1 (Insert employee name in HR system)"
                    fi
                fi

                if [ -f "$starter" ]; then
                    echo "Employee starter file for $name exists"
                fi
            ;;
            h)
                echo "Script requirements: [-a] [-b] [-c] [-d] [-e <value>]"
            ;;
            *)
                echo "Available options: [-a|-b|-c|-d|-e] only"
            ;;
        esac
done

Last updated

Was this helpful?