How to implement logic to parse a

Hi here!

Today I'm going on to share bash code allows to parse key/value input parameters.
 

function help() {
    echo "Put help info here"
}
for arg in "$@"; do
    case "$key" in
        "--key-1")
            export KEY_1=$arg
        ;;
        "--key-2" )
            export KEY_2=$arg
        ;;
        "--key-5" )
            export KEY_5=$arg
        ;;
        * )
            if [[ $key != "" ]]; then
                echo "UNKNOWN OPTION: $key"
                help
                exit 1
            fi
    ;;
    esac
    if [[ $key == "" ]]; then
        key=$arg
    fi
    if [[ $key == "--help" ]]; then
        help
        exit 1
    fi
    if [[ $arg != $key ]]; then
        key=""
    fi
done
echo "KEY_1: $KEY_1"
echo "KEY_2: $KEY_2"
echo "KEY_5: $KEY_5"

This approach you can use to parse input arguments inside the script.

Have a good day!

Enjoy!