Aller au contenu

Les conditions


La clause IF

#!/bin/bash

printf "Enter your name: "
read NAME
echo "Hello $NAME !"
printf "Please, enter a number: "
read NUMBER

if (( "$NUMBER" < "0" )); then
    echo "$NUMBER is negative !"
elif (( "$NUMBER" == "0" )); then
    echo "$NUMBER is null !"
else
    echo "$NUMBER is positive !"
fi

La clause IF..ELSE

#!/bin/bash

printf "Enter your name: "
read NAME
echo "Hello $NAME !"
printf "Please, enter a number: "
read NUMBER

if (( "$NUMBER" < "0" )); then
    echo "$NUMBER is negative !"
elif (( "$NUMBER" == "0" )); then
    echo "$NUMBER is null !"
else
    echo "$NUMBER is positive !"
fi

La clause IF..ELIF..ELSE

#!/bin/bash

printf "Enter your name: "
read NAME
echo "Hello $NAME !"
printf "Please, enter a number: "
read NUMBER

if (( "$NUMBER" < "0" )); then
    echo "$NUMBER is negative !"
elif (( "$NUMBER" == "0" )); then
    echo "$NUMBER is null !"
else
    echo "$NUMBER is positive !"
fi

Partagez sur les réseaux sociaux

Commentaires