Jump to content

Bash (Unix shell): Difference between revisions

Line 40: Line 40:
# String has length non-zero
# String has length non-zero
[ -n $STR ]
[ -n $STR ]
</syntaxhighlight>
<syntaxhighlight lang="bash">
# 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 ]
  then echo "Please run as root"
  exit
fi
</syntaxhighlight>
</syntaxhighlight>