Bash Script Snippets
There are a few bash snippets that I use very frequently in my bash scripts. Here is my collection.
Ensure root user
This will stop a script from executing if the root user isn't running it.
#check if root if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" <& exit; fi
Checks if usid is 0, if not exists.
Import an dotenv file
Stores information from a dotenv file to bash variables
export $(grep -v '^#' .env | xargs)