]> git.bundesbrandschatzamt.de Git - emacsconfig.git/commitdiff
updating templates/default-sh.sh
authorAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Fri, 19 Aug 2016 14:43:35 +0000 (16:43 +0200)
committerAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Fri, 19 Aug 2016 14:43:35 +0000 (16:43 +0200)
- better parsing of parameters with getopt for bash scripts.

Signed-off-by: Andreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
templates/default-sh.sh

index df931570cae4815da6567e5c40914ec40ad83a11..4dbbb2f1dc1622b0bb087b0eb01305453259acd6 100755 (executable)
  --man,  -m   to get this man page.
  --verbose, -v be more verbose.
 
+=head1 EXAMPLES
+
+  `(upcase (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))` -p password
+
+
 =cut
 
 
 # parse parameters
-
-for param in "$@"
-do
-    case $param in
-       -k|--keep)
-           KEEP=1
-           shift # past argument=value
-           ;;
-       -v|--verbose)
-           VERBOSE=1
-           shift # past argument=value
-           ;;
-       -h|--help)
-           pod2usage \$0
-           exit
-           ;;
-       -m|--man)
-           perldoc \$0
-           exit
-           ;;
-       *)
-           echo "unknown option $param"
-           echo
-           pod2usage \$0
-           exit
-           ;;
+TEMP=\`getopt -o mhvp --long man,help,verbose,password -n '`(downcase (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))`' -- "$@"\`
+
+while true; do
+    case "\$1" in
+       -p | --password ) PASSWORD="$2"; shift 2 ;;
+       -h | --help ) pod2usage \$0; exit ;;
+       -m | --man ) perldoc \$0; exit ;;
+       -v | --verbose ) VERBOSE=1; shift ;;
+       * ) break ;;
     esac
 done
 
 EXITCODE=0
 
+if [ -z "${PASSWORD}" ]; then
+    read -s -p "Password: " PASSWORD
+    echo
+fi
+
+if [ -z "${PASSWORD}" ]; then pod2usage $0; exit; fi
+
 $0
 
 :<<=cut