| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # getopt-simple.sh |
| 3 | # Author: Chris Morgan |
| 4 | # Used in the ABS Guide with permission. |
| 5 | |
| 6 | |
| 7 | getopt_simplescip-shell shell abs-guide 10-4 getopt_simple().() |
| 8 | { |
| 9 | echoscip-shell system . . echo. "getopt_simple()" |
| 10 | echoscip-shell system . . echo. "Parameters are '$*'" |
| 11 | until [scip-shell system . . `[`. -z "$1" ] |
| 12 | do |
| 13 | echoscip-shell system . . echo. "Processing parameter of: '$1'" |
| 14 | if [scip-shell system . . `[`. ${1:0:1} = '/scip-shell filesystem . . `/`.' ] |
| 15 | then |
| 16 | tmp=${1:1} # Strip off leading '/' . . . |
| 17 | parameter=${tmp%%=*} # Extract name. |
| 18 | value=${tmp##*=} # Extract value. |
| 19 | echoscip-shell system . . echo. "Parameter: '$parameter', value: '$value'" |
| 20 | eval $parameter=$value |
| 21 | fi |
| 22 | shift |
| 23 | done |
| 24 | } |
| 25 | |
| 26 | # Pass all options to getopt_simple(). |
| 27 | getopt_simplescip-shell shell abs-guide 10-4 getopt_simple(). $* |
| 28 | |
| 29 | echoscip-shell system . . echo. "test is '$test'" |
| 30 | echoscip-shell system . . echo. "test2 is '$test2'" |
| 31 | |
| 32 | exit 0 # See also, UseGetOpt.sh, a modified version of this script. |
| 33 | |
| 34 | --- |
| 35 | |
| 36 | shscip-shell system . . sh. getopt_example.sh /test=value1scip-shell filesystem . . `/test=value1`. /test2=value2scip-shell filesystem . . `/test2=value2`. |
| 37 | |
| 38 | Parameters are '/test=value1 /test2=value2scip-shell filesystem . . `/test=value1 /test2=value2`.' |
| 39 | Processing parameter of: '/test=value1scip-shell filesystem . . `/test=value1`.' |
| 40 | Parameter: 'test', value: 'value1' |
| 41 | Processing parameter of: '/test2=value2scip-shell filesystem . . `/test2=value2`.' |
| 42 | Parameter: 'test2', value: 'value2' |
| 43 | testscip-shell system . . test. is 'value1' |
| 44 | test2 is 'value2' |
| 45 |