| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # match-string.sh: Simple string matching |
| 3 | # using a 'case' construct. |
| 4 | |
| 5 | match_stringscip-shell shell abs-guide 10-4 match_string(). () |
| 6 | { # Exact string match. |
| 7 | MATCH=0 |
| 8 | E_NOMATCH=90 |
| 9 | PARAMS=2 # Function requires 2 arguments. |
| 10 | E_BAD_PARAMS=91 |
| 11 | |
| 12 | [scip-shell system . . `[`. $# -eq $PARAMS ] || return $E_BAD_PARAMS |
| 13 | |
| 14 | case "$1" in |
| 15 | "$2") return $MATCH;; |
| 16 | * ) return $E_NOMATCH;; |
| 17 | esac |
| 18 | |
| 19 | } |
| 20 | |
| 21 | |
| 22 | a=one |
| 23 | b=two |
| 24 | c=three |
| 25 | d=two |
| 26 | |
| 27 | |
| 28 | match_stringscip-shell shell abs-guide 10-4 match_string(). $a # wrong number of parameters |
| 29 | echoscip-shell system . . echo. $? # 91 |
| 30 | |
| 31 | match_stringscip-shell shell abs-guide 10-4 match_string(). $a $b # no match |
| 32 | echoscip-shell system . . echo. $? # 90 |
| 33 | |
| 34 | match_stringscip-shell shell abs-guide 10-4 match_string(). $b $d # match |
| 35 | echoscip-shell system . . echo. $? # 0 |
| 36 | |
| 37 | |
| 38 | exit 0 |