Joel Dare

Bash Script Template

A simple bash or zsh script example that accepts a command line argument, shows it’s own usage syntax and verifies that a command executed correctly.

#!/bin/sh

# Grab the command line options
while getopts u: flag
do
    case "${flag}" in
        u) url=${OPTARG};;
    esac
done

# If the URL is blank show the syntax
if [ -z "$url" ]
then
    echo "Backup, version 1.0.0, Joel's simple notion backup script"
    echo "Usage: backup.sh [option] ..."
    echo "Options:"
	echo "  -u     The URL of the backup file you requested through Notion Settings (use quotes)"
    echo "Example:"
    echo "  ./backup.sh -u \"https://www.example.com/example.zip\""
    exit
fi

# Download the notion backup file using curl and exit on errors
curl -o /tmp/notion.zip "$url"
if [ $? != 0 ]
then
    echo "ERROR: Unabled to dowload."
    exit;
fi