-1
APPLICATION_VERSION="1.0"
APPLICATION_HELP="SOME HELP TEXT"

function help(){
        echo "h${APPLICATION_HELP}"
        exit 0
}
help

function versionapp(){
    echo "v${APPLICATION_VERSION}"
    exit 0
}
versionapp

function check(){
    while getopts "vh" option; do
    case $option in
    v) 
     versionapp
    ;;
    h) 
     help
    ;;
    \? )
    echo "You have entered an invalid option. The valid options are [r], [y], and [g]"
    ;;
    esac
    done
}
check

Hi all usually I would not need to ask around this simple task- however, stuck here and can't figure out what is going wrong.

Since I spent quite a bit of time I would appreciate the correct code and explanation?

JnooriRS
  • 103
  • 11
  • 1
    _I would appreciate the correct code_ You have not specified what the correct code is supposed to do, i.e. what outcome you expect, compared to what output you actually see. – user1934428 Jul 13 '22 at 09:16

1 Answers1

1

You are running your functions right after declaring them, here is the first one:

...
function help(){
        echo "h${APPLICATION_HELP}"
        exit 0
}
help
# your script will end here because of 'exit 0' in help function
...

Move exit 0 out from functions, and use it only where it's needed.

Ivan
  • 6,188
  • 1
  • 16
  • 23