Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add yn_yes and yn_no #4

Open
ChillerDragon opened this issue Jan 28, 2020 · 1 comment
Open

Add yn_yes and yn_no #4

ChillerDragon opened this issue Jan 28, 2020 · 1 comment

Comments

@ChillerDragon
Copy link
Member

yn_yes is a function that takes a string and then acts as a prompt. The implementation could look like this:

functuion yn_yes() {
        read -p "$1 [Y/n]" -n 1 -r
        echo 
        if [[ $REPLY =~ ^[Yy]$ ]]; then return 1; fi
}

A use case might be:

if yn_yes "do you really want to do xyz?"
then
       proceed
fi
exit

And yn_no is the default no case.

@ChillerDragon
Copy link
Member Author

ChillerDragon commented Jan 28, 2020

Also yn_abort could come in handy. It can be invoked after a critical warning if the user wants to continue or quit the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant