If loop in shell script

if script:
#!/bin/bash
echo -n "enter the key : "
read key
if [ $key -eq 1122 ]
then
   echo "you entered correct key"
fi
output:
enter the key : 1122
you entered correct key



if else script:
#!/bin/bash
echo -n "enter the key : "
read key
if [ $key -eq 1122 ]
then
    echo "you entered correct key"
else
    echo "you entered wrong key"
fi
output:
i)
enter the key : 100
you entered wrong key
ii)
enter the key : 1122
you entered correct key


nested if:
#!/bin/bash
echo "1. windows"
echo "2. Linux "
echo -n "which operating you like to work 1 or 2 ? "
read sel
if [ $sel -eq 1 ]
then
    echo "you selected windows"
else
    if [ $sel -eq 2 ]
    then
        echo "you selected linux"
    else
        echo "wrong selection select 1 or 2"
    fi
fi
output:
i)
1. windows
2. Linux
which operating you like to work 1 or 2 ? 1
you selected windows
ii)
1. windows
2. Linux
which operating you like to work 1 or 2 ? 2
you selected linux
iii)
1. windows
2. Linux
which operating you like to work 1 or 2 ? 3
wrong selection select 1 or 2
 

No comments:

Post a Comment