source: vendor/bash/3.1-p17/examples/functions/ksh-compat-test

Last change on this file was 3228, checked in by bird, 18 years ago

bash 3.1

File size: 1.2 KB
Line 
1#
2# replacements for test/[ that do arithmetic expansion on the operands to
3# the arithmetic operators, like ksh.
4#
5function 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
20function [()
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
35q=7
36
37[ q -lt 10 ]
38echo $?
39[ $q -lt 10 ]
40echo $?
Note: See TracBrowser for help on using the repository browser.