dimanche 19 janvier 2020

Counting the number of inputs provided by user

Description: I have a script that begins with a warning/question posed to user. I need the user to answe with yes/y or no/n.

Issue: Though I have a conditional to make sure the user provides one of the following answers presented above I also need to make that only ONE input is provided by the user. I have attempted using

[ "$#" -eq 1 ] or [ $# -eq 1 ] neither of these coniditionals seems to work to solve the problem

here is what I have thus far:...

#!/bin/bash
#
# Descritpion: some Windows OS script
#
# 

printf "(!)WARNING(!): 1. The this program is ONLY compatible with Windows operating systems. "
printf "2. You will NEED to be logged in as an ADMIN in order to fully make use of the '*****' script.\n" 
printf "Would you like to continue? yes or no (y/n): "

#would it be cleaner to use "case" rather than a "while" w/ multiple conditionals? (01.19.2020)
read opt

while (true)
do
        if [ $opt == yes ] || [ $opt == y ]
        then
                printf "continue. \n"
                break

        elif [ $opt == no ] || [ $opt == n ]
        then
                printf "OK, exiting the script! \n"
                exit 0

        #elif [ "$#" -ne 1 ]
        #then
        #       "Too many arguments have been provided, please try again. \n"
        #       read opt
        else
                printf "The opition you provided is not recognized, please try again. \n"
                read opt
        fi
done

Aucun commentaire:

Enregistrer un commentaire