Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- ############################################
- # Define variables
- # Script Information
- script="Hello World Example"
- time="$(date)" # The current time and date
- TITLE="Hello World Example" # This is the title of your
- AUTHOR="textandmetal" # Who wrote this script
- TAGLINE="A super simple bash tool" # Tagline for your script in man page
- manpagename=$(printf "$TITLE" | tr '[:lower:]' '[:upper:]') # This transforms the $title variable to uppercase for man page
- man_page(){
- # This is the help page that is triggered by the -h flag
- # Give the user important information and include common
- # examples of usage
- printf "
- $manpagename(1) User Commands MANPAGE(1)
- NAME
- $TITLE - $TAGLINE
- SYNOPSIS
- $TITLE [OPTION]...
- DESCRIPTION
- A simple bash script to demonstrate flags and some basic
- options for it.
- -h
- Show this man page
- -l
- View the licence for this script
- -d
- Debug your script, the script will start but has
- the -set x option enabled
- "
- }
- view_licence(){
- # The licence for this script, it takes the $AUTHOR and $TILE variable
- printf "
- $TITLE
- MIT License
- Copyright (c) 2019 $AUTHOR
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "'"Software"'"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "'"AS IS"'", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- "
- }
- txtred=$(tput setaf 1)
- txtgrn=$(tput setaf 2)
- txtylw=$(tput setaf 3)
- txtblu=$(tput setaf 4)
- txtpur=$(tput setaf 5)
- txtcyn=$(tput setaf 6)
- bold=$(tput bold)
- txtrst=$(tput sgr0)
- ##############################################################################
- ############################### debug_program ################################
- ##############################################################################
- # This launches the script in a simple debugging mode
- debug_program(){
- set -x
- start_program
- set +x
- }
- ##############################################################################
- ##############################################################################
- ##############################################################################
- ############################### start_program ################################
- ##############################################################################
- # This is the main part of the script that launches on execution without flags
- start_program(){
- echo "Hello World"
- }
- ##############################################################################
- ##############################################################################
- # getopts for options
- while getopts dhl option
- do
- case "${option}"
- in
- l) VIEWLICENCE="view_licence";;
- h) MANPAGE="man_page";;
- d) DEBUG="debug_program" ;;
- esac
- done
- # Main Logic
- while true
- do
- #clear
- if [ $OPTIND -eq 1 ]; then start_program; fi
- shift $((OPTIND-1))
- #printf "$# non-option arguments"
- $MANPAGE
- $VIEWLICENCE
- $DEBUG
- exit
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement