Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Jun 2002 15:00:17 -0700 (PDT)
From:      Giorgos Keramidas <keramida@FreeBSD.org>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/39198: sh aborts on variables with periods
Message-ID:  <200206142200.g5EM0HN67513@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/39198; it has been noted by GNATS.

From: Giorgos Keramidas <keramida@FreeBSD.org>
To: parv <parv@pair.com>
Cc: Frank v Waveren <fvw@var.cx>, bug-followup@FreeBSD.org
Subject: Re: bin/39198: sh aborts on variables with periods
Date: Fri, 14 Jun 2002 23:21:43 +0300

 On 2002-06-12 20:20 -0400, parv wrote:
 > in message <1023918173HKC.fvw@yendor.var.cx>,
 > wrote Frank v Waveren thusly...
 > > On Wed, Jun 12, 2002 at 05:41:11PM -0400, parv wrote:
 > > >     if test $RANDOM = $RANDOM
 > >
 > > omg, you wicked wicked man. That will mysteriously misdetect on ksh/bash
 > > once in 32767 times. Please don't.
 >
 > oh, come on, i am merely conveying what i got in the mail!
 > anyway, i tried...
 
 [snipetry of 32767 tests of a RNG ]
 
 You're just too damn lucky that this didn't get you the same random
 number.  Your test of $RANDOM = $RANDOM will very possibly fail if
 your RNG allows multiple occurences of the same number to appear in
 the stream of random numbers, but will only fail very rarely, and will
 go unnoticed until it's very late :P
 
 If you absolutely *must* use $RANDOM for making this test, you should
 probably use something like:
 
 	if [ X"${RANDOM}" = X"" ]; then
 		# $RANDOM failed
 	else
 		if echo "${RANDOM}" | \
 		    grep '^[[:digit:]]\+$' >/dev/null 2>&1 ;then
 			# # $RANDOM exists and works as expected
 		else
 			# $RANDOM isn't null, but is not a number
 			# either.  Oops!
 		fi
 	fi
 
 - Giorgos
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200206142200.g5EM0HN67513>