Skip to content

Instantly share code, notes, and snippets.

@KathanP19
Created December 30, 2021 06:05
Show Gist options
  • Save KathanP19/20e9ec4d6e51418f574245a3b3cf106f to your computer and use it in GitHub Desktop.
Save KathanP19/20e9ec4d6e51418f574245a3b3cf106f to your computer and use it in GitHub Desktop.

Revisions

  1. KathanP19 created this gist Dec 30, 2021.
    49 changes: 49 additions & 0 deletions option_inside_long.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    #!/bin/bash

    function first(){
    echo "First Function";
    }

    function second(){
    echo "Second Function";
    }

    function third(){
    echo "Third Function";
    }

    while [ -n "$1" ]; do
    case "$1" in
    first) first;
    OPTIND=2
    while getopts "lo:" opt; do
    case "${opt}" in
    l) echo "Passsed In Option of First FUnction";
    ;;
    o) echo "$OPTARG"
    ;;
    esac
    done
    break ;;
    second) second;
    OPTIND=2
    while getopts "l" opt; do
    case "${opt}" in
    l) echo "Passsed In Option of second FUnction";
    ;;
    esac
    done
    break ;;
    -help|--help|-h) echo "Usage: ";
    echo -e " $0 first -l -o Argument_to_Param";
    echo -e " $0 second -l";
    exit 2;;
    *)
    if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
    echo "Non-option argument: '-${OPTARG}'";
    fi
    ;;

    esac
    shift
    done