Script Logik
Alle wichtigen Bash Kondizionen und ihre Anwendung
If, Elif, Else
#!/bin/bash
read -p "Enter your Age: " AGE
if [ $AGE -ge 80 ]
then
echo "You are very old"
elif [ $AGE -ge 40 ]
then
echo "You are old"
elif [ $marks -le 18 ]
then
echo "You are very young"
elif [ $marks -le 30 ]
then
echo "You are young"
else
echo "You are the Rest"
fi
Case
#!/bin/bash
read -p "systemctl <your input> nginx" systemctl_cmd
case "$systemctl_cmd" in
start)
systemctl start nginx ;;
stop)
systemctl stop nginx ;;
restart)
systemctl restart nginx ;;
*)
echo "Your input was not vaild "
esac
Funktion
#!/bin/bash
#Function <-- Description
function delete_file {
rm $1
}
#Script to call function
delete_file /root/useless_file
While
Inkrementelle Schlaufe
#!/bin/bash
i=0
while [ $i -lt 3 ]
do
echo $i
((i++))
done
Unendliche Schlaufe
#!/bin/bash
while true;
do
echo "Spam Message"
done