Linux Console / Shell

  • Shell scripts start with a shebang (#!) and the shell path - so for bash #! /bin/bash
  • File extension .sh
  • Must have execution rights - add with chmod u+x
Execute with ./
# - comment
name=Markus - define a variable
$name - use a variable
#! /bin/bash # A simple variable example greeting=Hello name=Markus echo $greeting $name
read a - prompt, entered text will be saved in variable a
read -p "Enter your age" variable_age - prompt with a custom message
#! /bin/bash echo "Enter a number" read a echo "Enter a number" read b var=$((a+b)) echo $var
If then else
#! /bin/bash read x read y if [ $x -gt $y ] then echo X is greater than Y elif [ $x -lt $y ] then echo X is less than Y elif [ $x -eq $y ] then echo X is equal to Y fi

Leave a comment