Skip to content

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

Closed
@giulianoassaggio

Description

@giulianoassaggio

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions