init version.
[bush.git] / examples / functions / ksh-compat-test
blob919d82bcd304ef9e505e1b795c12db2d21533685
2 #  Chet Ramey <chet.ramey@case.edu>
4 #  Copyright 1999 Chester Ramey
6 #   This program is free software; you can redistribute it and/or modify
7 #   it under the terms of the GNU General Public License as published by
8 #   the Free Software Foundation; either version 2, or (at your option)
9 #   any later version.
11 #   TThis program is distributed in the hope that it will be useful,
12 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #   GNU General Public License for more details.
16 #   You should have received a copy of the GNU General Public License
17 #   along with this program; if not, write to the Free Software Foundation,
18 #   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # replacements for test/[ that do arithmetic expansion on the operands to
21 # the arithmetic operators, like ksh.
23 function test()
25         local -i n1 n3
26         case "$#" in
27         3)      case "$2" in
28                 -lt|-gt|-eq|-ne|-le|-ge)        n1=$(( $1 ))
29                                                 n3=$(( $3 ))
30                                                 builtin test "$n1" $2 "$n3"
31                                                 return $?;;
32                 *)      builtin test "$@" ;;
33                 esac;;                                                          
34         *)      builtin test "$@" ;;
35         esac
38 function [()
40         local -i n1 n3
41         case "$#" in
42         4)      case "$2" in
43                 -lt|-gt|-eq|-ne|-le|-ge)        n1=$(( $1 ))
44                                                 n3=$(( $3 ))
45                                                 builtin [ "$n1" $2 "$n3" ]
46                                                 return $?;;
47                 *)      builtin [ "$@" ;;
48                 esac;;                                                          
49         *)      builtin [ "$@" ;;
50         esac
53 q=7
55 [ q -lt 10 ]
56 echo $?
57 [ $q -lt 10 ]
58 echo $?