mercredi 28 février 2018

Shell script if-else case

I wrote the below script to take input interactively servername and service name. This repeats asking the inputs when y is given as input at the end of the while loop.

key='y';
service='';
serverName='';
while [[ $key == 'y' ]]; do
    echo -e "\nEnter serverName  : "
    read serverName
    echo -e "\nEnter Service Name  : "
    read service
    if [[ ! -z "$service" ] && [ ! -z "$serverName" ]]; then
        echo -e "startService $serverName $service"
        #echo -e " Atleast one input is null"
    else
        echo -e " Atleast one input is null"
    fi
    echo -e "Enter y to repeat this step. Enter n to exit :"
    read key
done

Aucun commentaire:

Enregistrer un commentaire