I need to write a one script which does a number functions with these options in any order.
backup *default file to be restored (no options)
backup *change default config file location
backup *errorlogging only
backup *fullerrorlogging
restore *default last backup restored
restore *restore by filename
restore *list all backups
restore *list backups by name
restore *list contents of last backup
restore *change default restore location to new one
restore *carry out diff on tar contents
My solution is to write functions for each task in script but how should I parse the options to the script - was thinking of the case within a case below - is this the best way to go - will I have problems? is there an easier way?
But main question is how do you run a case with no options - as in a default action for the script below -
z={(( $# )) || printf '%s\n' 'No arguments'}
echo "$z"
Then use "$z" as an option??? would this work?
Code:
#!/bin/bash
# set -xv
######################################################
# Setting up variables for script #
######################################################
z={(( $# )) || printf '%s\n' 'No arguments'}
echo "$z"
while getopts "b:r:h" OPTION; do
case "$OPTION" in
b)
# if [[ ! $OPTARG ]]; then echo "No option."
# else
case "${OPTARG}" in
f)
echo "LOGFLAG=false"
echo "FULL_LOGGING=true"
echo "logging_option"
# [[ ! $OPTARG ]] && echo "No option."
;;
e)
echo "ERRORLOGGING AS NORMAL"
;;
esac;;
r)
case "${OPTARG}" in
name)
echo "restore_filename"
;;
latest)
echo "restore_latest"
;;
listall)
echo "listall"
;;
project)
echo "project_timestamp"
;;
lastcontents)
echo "last_contents"
;;
directory)
echo "RESTORE_FILES_DIRECTORY="
;;
compare)
echo "Compare"
;;
esac;;
h)
echo " help_action"
;;
?)
echo "HELLP HELP"
;;
"$z")
echo "NO ENRTY"
;;
esac