BASH
Alles Rund um das Bash Scripten

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

Skript Syntax
Bash syntaxe
https://acloudguru.com/blog/engineering/conditions-in-bash-scripting-if-statements

Dateiexistenz
[ -f Filepath ] 

 Dies testet ob die Datei existiert.

Kleiner/Grösser
[ $x -le 3 ] 

 Dies testet ob die x kleiner gleich (lower equal - le) ist. 

 [ $x -ge 3 ] 

 Dies testet ob die x grösser gleich (greather equal - ge) ist.

Datei-lesbar
[ -r Filepath ] 

 Dies testet ob die Datei lesbar ist.

Verneinung
Alle möglichen Syntaxe können in BASH mit einem "!" verneint werden. 

  