Add A Help Dialog To Bash Scripts

Below is a quick and simple case statement that functions as a help dialog whenever the script is run with -h, –help, or -help.

Code snippet:

#!/bin/bash

# Help dialog
case "$1" in
-h|--help|-help) # Argument to check for
  # If help argument was passed then run this
  print "This is a sample help dialog created using a simple case statement,\n";
  print "for more information on case statements please visit https://teachmelinux.com";
  exit 0; # Exit cleanly after showing help dialog.
;;
esac;

I hope this quick post was useful for you, please don’t forget to like/share/comment. Thanks!

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *