Line | |
---|
1 | #
|
---|
2 | # replacements for test/[ that do arithmetic expansion on the operands to
|
---|
3 | # the arithmetic operators, like ksh.
|
---|
4 | #
|
---|
5 | function test()
|
---|
6 | {
|
---|
7 | local -i n1 n3
|
---|
8 | case "$#" in
|
---|
9 | 3) case "$2" in
|
---|
10 | -lt|-gt|-eq|-ne|-le|-ge) n1=$(( $1 ))
|
---|
11 | n3=$(( $3 ))
|
---|
12 | builtin test "$n1" $2 "$n3"
|
---|
13 | return $?;;
|
---|
14 | *) builtin test "$@" ;;
|
---|
15 | esac;;
|
---|
16 | *) builtin test "$@" ;;
|
---|
17 | esac
|
---|
18 | }
|
---|
19 |
|
---|
20 | function [()
|
---|
21 | {
|
---|
22 | local -i n1 n3
|
---|
23 | case "$#" in
|
---|
24 | 4) case "$2" in
|
---|
25 | -lt|-gt|-eq|-ne|-le|-ge) n1=$(( $1 ))
|
---|
26 | n3=$(( $3 ))
|
---|
27 | builtin [ "$n1" $2 "$n3" ]
|
---|
28 | return $?;;
|
---|
29 | *) builtin [ "$@" ;;
|
---|
30 | esac;;
|
---|
31 | *) builtin [ "$@" ;;
|
---|
32 | esac
|
---|
33 | }
|
---|
34 |
|
---|
35 | q=7
|
---|
36 |
|
---|
37 | [ q -lt 10 ]
|
---|
38 | echo $?
|
---|
39 | [ $q -lt 10 ]
|
---|
40 | echo $?
|
---|
Note:
See
TracBrowser
for help on using the repository browser.