From owner-freebsd-questions Wed May 7 09:08:25 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.5/8.8.5) id JAA29173 for questions-outgoing; Wed, 7 May 1997 09:08:25 -0700 (PDT) Received: from mail.EUnet.hu (www.eunet.hu [193.225.28.100]) by hub.freebsd.org (8.8.5/8.8.5) with ESMTP id JAA29147 for ; Wed, 7 May 1997 09:08:20 -0700 (PDT) Received: by mail.EUnet.hu, id SAA16561; Wed, 7 May 1997 18:08:11 +0200 Received: (from zgabor@localhost) by CoDe.hu (8.7.5/8.7.3) id RAA00810; Wed, 7 May 1997 17:09:53 +0200 (MET DST) From: Zahemszky Gabor Message-Id: <199705071509.RAA00810@CoDe.hu> Subject: Re: tests To: freebsd-questions@freebsd.org (FreeBSD questions) Date: Wed, 7 May 1997 17:09:53 +0200 (MET DST) Cc: un_x@anchorage.net In-Reply-To: from Steve Howe at "May 6, 97 07:54:44 am" X-Mailer: ELM [version 2.4ME+ PL11 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk > > i guess this is the way "test"s work, in case > it gives anyone new to sh programming some troubles ... > ------------------------------------------------------------------------ > all integers are strings, but only numeric strings are "integers". > > [ x ] only fails on the null string, ""(ascii 0), not on 0 (ascii 48). Yes. > any test, results in a 0(ascii 0) or 1(ascii 1). No. Any test result in a 0 status code or a non-0 status code. -- man test RETURN VALUES The test utility exits with one of the following values: 0 expression evaluated to true. 1 expression evaluated to false or expression was missing. >1 An error occurred. -- > ! x is only true if x is ""(ascii 0), so it may only be used to > test for the null string ("") and the result of a test([]). > > therefore, -gt, -lt, -ge, -le may only be used on numeric strings, > the "-" tests force a stringTOint conversion for the comparison, > is my guess. Yes, I think so. (conversion) > > and so -eq/= and -ne/!= may be used interchangably, as long as you > never use an alphabetic character in a -eq/-ne comparison, > since a stringTOint conversion must be done w/ -ne and -eq.. > ------------------------------------------------------------------------- > i'm "fairly" sure this is correct! It would be better to use string compare on strings, and numeric compare on numerals. As I've written in a previous letter: $ test 01 -eq 1 ; echo $? 0 $ test 01 = 1 ; echo $? 1 So = and -eq are NOT interchargeable! I think, when = returns true, than -eq should be, too, but on the other cases, it's not true. Bye, Gabor -- #!/bin/ksh Z='21N16I25C25E30, 40M30E33E25T15U!' ;IFS=' ABCDEFGHIJKLMNOPQRSTUVWXYZ ';set $Z;for i { [[ $i = ? ]]&&print $i&&break;[[ $i = ??? ]]&&j=$i&&i=${i%?};typeset -i40 i=8#$i;print -n ${i#???};[[ "$j" = ??? ]]&&print -n "${j#??} "&&j=;typeset +i i;};IFS=' 0123456789 ';set $Z;X=;for i { [[ $i = , ]]&&i=2;[[ $i = ?? ]]||typeset -l i;X="$X $i";typeset +l i;};print "$X"