Jump to content

Bash (Unix shell): Difference between revisions

 
Line 20: Line 20:
[https://linuxize.com/post/bash-if-else-statement/ https://linuxize.com/post/bash-if-else-statement/]
[https://linuxize.com/post/bash-if-else-statement/ https://linuxize.com/post/bash-if-else-statement/]
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
if [[ $VAR -gt 10 ]] then
if [[ $VAR -gt 10 ]]; then
   echo "The variable is greater than 10."
   echo "The variable is greater than 10."
elif [[ $VAR -eq 10 ]] then
elif [[ $VAR -eq 10 ]]; then
   echo "The variable is equal to 10."
   echo "The variable is equal to 10."
else
else
Line 44: Line 44:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
# Check if user is root (https://stackoverflow.com/questions/18215973/how-to-check-if-running-as-root-in-a-bash-script)
# Check if user is root (https://stackoverflow.com/questions/18215973/how-to-check-if-running-as-root-in-a-bash-script)
if [ "$EUID" -ne 0 ]
if [ "$EUID" -ne 0 ]; then
   then echo "Please run as root"
   echo "Please run as root"
   exit
   exit
fi
fi