Skip to content

Handling the user's reply based on (yes/no) conditions #1

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

Closed
giulianoassaggio opened this issue Nov 13, 2023 · 0 comments
Closed

Handling the user's reply based on (yes/no) conditions #1

giulianoassaggio opened this issue Nov 13, 2023 · 0 comments

Comments

@giulianoassaggio
Copy link

Concerning code blocks starting on lines 133, 96 and 156, I would recommend choosing a single-character-based reply (or, to check the exact string pattern, as shown at the end of this issue) to avoid mismatching.
You are checking case $answer in [Yy]*, which means "every string starting with 'y' or 'Y', of any length". I'd suggest using just the options (y/n), and adding a check on the string length, to be a little more certain about what the user is typing:

read -p "Do you want to disable Bluetooth services to improve security? (y/n) " answer
echo    # new line (optional)
if [[ $answer =~ ^[Yy]$ ]]
then
    # Disable Bluetooth services using systemctl
fi
  • =~: string matching
  • ^[Yy]$: string starts with Y or y and ends after one char

This way, ANY string different from "y" or "Y" will guarantee that the code block is skipped (so, there's no need to check the "n/N" case).
If you prefer the user to write exactly the string "yes", you can use the following pattern: ^[Yy][Ee][Ss]$

my2sats

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

2 participants