case function for no-argument - default function for script?
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:
|
check out getopts you might like that.
|
Quote:
|
Help?!!
How can I set the case to pick either b or r and not both?
[/code] #!/bin/bash # set -xv ###################################################### # Setting up variables for script # ###################################################### while getopts "b:r:h" OPTION; do case "$OPTION" in b) while getopts "f:e:" OPTION2; do case "$OPTION2" in f) echo "FULL_LOGGING=true" ;; e) echo "ERRORLOGGING AS NORMAL" ;; esac done;; 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" ;; *) echo "NO ENRTY" ;; esac done [code] |
All times are GMT -5. The time now is 10:15 AM. |