Friday, December 2, 2022

switch case example in bash script

#! /bin/bash


echo -en "Enter your logins\nUsername: "

read user_name 

echo -en "Password: "

read user_pass 

while [ -n $user_name -a -n $user_pass ]

do


case $user_name in

    ro*|admin)

        if [ "$user_pass" = "Root" ];

        then

            echo -e "Authentication succeeded \ n You Own this Machine"

    break

        else

            echo -e "Authentication failure"

            exit

        fi

    ;;

    jenk*)

if [ "$user_pass" = "Jenkins" ];

then

echo "Your home directory is /var/lib/jenkins"

    break

else

        echo -e "Authentication failure"

fi

        break

    ;;

    *)

        echo -e "An unexpected error has occurred."

        exit

    ;;

esac


done


Source: BASH "switch case" in Linux with practical example - Linux Cent

No comments:

Post a Comment