0

I am writing a script which displays input options in a while loop provided by a function user_input() and set values depending on user input, then I call another function user_info(). If a user made a mistake I am trying to offer him to go back to correct his input. So if a user set $var by mistake to "Yes" he can go back an reset the option! Assuming the user reset $var to "No", is there any way not to resume at code (2), rather to jump to the elif statement and run code (3) ? If the question is not clear I can post my code to make it clearer. Thanks a lot:

user_input(){
    while true; do
        input option $var
    done
    user_info
}

user_info(){
    some code
    if [ "${var}" = "Yes" ]; then
        code (1)
        if [ "${option}" = "back" ]; then
            user_input
        fi
        code (2)
    elif [ "${var}" = "No" ]; then
        code (3)
    fi
}
0

I think I found a solution by adding return after each call of the user_input() function like this, please correct me if I made a mistake. Thanks a lot:

user_input(){
    while true; do
        input option $var
    done
    user_info
}

user_info(){
    some code
    if [ "${var}" = "Yes" ]; then
        code (1)
        if [ "${option}" = "back" ]; then
            user_input
            return
        fi
        code (2)
    elif [ "${var}" = "No" ]; then
        code (3)
    fi
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.