Bash Script Skeleton

Check for number of arguments

#!/bin/bash
#
# .......... comment ............
#
NOW=$(date +"%Y-%m-%d-%H-%M-%S")
#
#
if [[ ! ("$#" == 1) ]]; then
  echo "One argument required."
  exit 1
fi
#
exit 0
#

Check if argument is empty

if [ -z "$1" ]; then
    echo 'Usage: $0 "<Comment>"'
    exit 1
fi

Sleep a random amount of time between 0 and 10 minutes

sleep $((RANDOM%600))

Check if file does not exist

if [ ! -f "$HOSTFILE" ]; then
  echo "File: $HOSTFILE does not exist"
  exit 1
fi

QR Code
QR Code tech:linux:bash_script_skeleton (generated for current page)