aboutsummaryrefslogtreecommitdiffstats
path: root/unix/getopt-simple.sh
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-01-19 19:19:24 +0800
committerAaron LI <aaronly.me@outlook.com>2017-01-19 19:19:24 +0800
commita1815079ad4ff8076eb33bbd3f6b50e5c1a66763 (patch)
tree6bb032fb65e39e307288163f3adc64c0b2ffbcf6 /unix/getopt-simple.sh
parent582e8827ad9fe6c7843d7f4ad86337b68270996f (diff)
downloadatoolbox-a1815079ad4ff8076eb33bbd3f6b50e5c1a66763.tar.bz2
Add various scripts
Diffstat (limited to 'unix/getopt-simple.sh')
-rwxr-xr-xunix/getopt-simple.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/unix/getopt-simple.sh b/unix/getopt-simple.sh
new file mode 100755
index 0000000..f5b06f0
--- /dev/null
+++ b/unix/getopt-simple.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+# getopt-simple.sh
+# Author: Chris Morgan
+# Used in the ABS Guide with permission.
+#
+# See also, UseGetOpt.sh, a modified version of this script.
+
+### example
+# $ sh getopt_example.sh /test=value1 /test2=value2
+
+# Parameters are '/test=value1 /test2=value2'
+# Processing parameter of: '/test=value1'
+# Parameter: 'test', value: 'value1'
+# Processing parameter of: '/test2=value2'
+# Parameter: 'test2', value: 'value2'
+# test is 'value1'
+# test2 is 'value2'
+###
+
+
+getopt_simple()
+{
+ echo "getopt_simple()"
+ echo "Parameters are '$*'"
+ until [ -z "$1" ]
+ do
+ echo "Processing parameter of: '$1'"
+ if [ ${1:0:1} = '/' ]
+ then
+ tmp=${1:1} # Strip off leading '/' . . .
+ parameter=${tmp%%=*} # Extract name.
+ value=${tmp##*=} # Extract value.
+ echo "Parameter: '$parameter', value: '$value'"
+ eval $parameter=$value
+ fi
+ shift
+ done
+}
+
+# Pass all options to getopt_simple().
+getopt_simple $*
+
+echo "test is '$test'"
+echo "test2 is '$test2'"
+
+exit 0