#!/bin/bash

helpmessage="This script showcases how to read arguments"

### get arguments
# while input array size greater than zero
while (($# > 0)); do
    if [ "$1" == "-h" -o "$1" == "-help" -o "$1" == "--help" ]; then
        shift; 
        echo "$helpmessage"
        exit;
    elif [ "$1" == "-f1" -o "$1" == "--flag1" ]; then
        # store what's passed via flag1 in var1
        shift; var1=$1; shift
    elif [ "$1" == "-f2" -o "$1" == "--flag2" ]; then
        shift; var2=$1; shift
    elif [ "$1" == "-f3" -o "$1" == "--flag3" ]; then
        shift; var3=$1; shift
    # if unknown argument, just shift
    else    
        shift
    fi
done

### main
# echo variable if not empty 
if [ ! -z $var1 ]; then echo "flag1 passed "$var1; fi
if [ ! -z $var2 ]; then echo "flag2 passed "$var2; fi
if [ ! -z $var3 ]; then echo "flag3 passed "$var3; fi