#!/bin/bash
#
# 'if' conditionals can be nested, but if you are confronted with several
# actions to take, it's better to use a 'case' statement.
# Syntax:
#   case EXPR in CASE1) COMMAND-LIST;; .. CASEN) COMMAND-LIST;; esac
#

case "$1" in
     start)
          echo "start option chosen"
          ;;
         
     stop)
          echo "stop option chosen"
          ;;
         
     status)
          if (( $# < 2 )); then
               echo "missing argument for status"
               exit 1
          else
               echo "status: " $2
          fi
          ;;

     *)
          echo "Usage: $0 {start|stop|status arg}"
          exit 1
esac

# Each CASE is an expression matching a pattern.
# The "|" symbol is used for separating multiple patterns.
# The ")" operator terminates a pattern list.
#

read -p "Do you want to continue? (y/n): " answer

case "$answer" in
    # This pattern matches any of the listed strings
    yes|YES|y|Y)
        echo "Proceeding..."
        # ... your code here ...
        ;;

    no|NO|n|N)
        echo "Aborting."
        exit 1
        ;;

    *)
        echo "Invalid input. Please answer yes or no."
        ;;
esac

# Another example:

filename="$1"

if [[ -z "$filename" ]]; then
    echo "Usage: $0 <filename>"
    exit 1
fi

case "$filename" in
    # Matches any string ending in .jpg or .jpeg
    *.jpg|*.jpeg)
        echo "'$filename' is a JPEG image."
        ;;

    # Matches any string ending in .png
    *.png)
        echo "'$filename' is a PNG image."
        ;;

    # Matches any string starting with "log" and ending in .txt
    log*.txt)
        echo "'$filename' is a log file."
        ;;

    # Matches a filename with exactly a 3-character extension
    *.*??)
        echo "'$filename' has a three-character extension."
        ;;

    # Matches any filename starting with a number
    [0-9]*)
        echo "'$filename' starts with a digit."
        ;;

    # Matches any hidden file (starts with a dot)
    .*)
        echo "'$filename' is a hidden file."
        ;;

    *)
        echo "Unknown file type for '$filename'."
        ;;
esac


