NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: standards/56663: Disable RANDOM variable in sh(1) POSIX mode
The following reply was made to PR standards/56663; it has been noted by GNATS.
From: Robert Elz <kre%munnari.OZ.AU@localhost>
To: Yetoo Happy <yetoohappy%gmail.com@localhost>
Cc: gnats-bugs%netbsd.org@localhost
Subject: Re: standards/56663: Disable RANDOM variable in sh(1) POSIX mode
Date: Tue, 25 Jan 2022 06:08:31 +0700
Date: Mon, 24 Jan 2022 14:21:34 -0800
From: Yetoo Happy <yetoohappy%gmail.com@localhost>
Message-ID: <CALT2f4vjTDbBjEZwLnVLcWAOahCeA0egUFV4XWNZ1BjHPOQLog%mail.gmail.com@localhost>
| can the class be changed to a change-request and moved to bin if
| applicable?
It could be.
| It would be helpful if the posix mode was strict like FreeBSD's sh where
| RANDOM doesn't work so it would be easier to vet a script's portability
| on NetBSD.
If a script is using $RANDOM other than as a source of (fairly weak)
random numbers, it definitely isn't portable - all you need to do is
search for RANDOM in the script, and if found, see how/why it is being used.
Does FreeBSD's sh support RANDOM at all (posix mode or otherwise) ?
Last time I looked it didn't (nor do some other shells). That's all OK,
they're not required to.
But RANDOM use isn't a question for the shell really, but the application,
which should really not be using that as a variable name -- unless it wants
random numbers, and then it needs to test to see if it works first, just:
if [ "$RANDOM" = "$RANDOM" ]; then fail 'No $RANDOM support in shell'; fi
(or similar) should be included (assuming a suitable fail() function exists,
otherwise send an error message and exit).
If you see something like that, then you can generally assume that any other
use of RANDOM in the script is probably OK (but not portable to all shells).
If not, and if RANDOM is used at all, it takes more careful analysis (but
either way, the script is not portable).
kre
ps: all shells (well, almost all shells) have all kinds of extensions to
POSIX, that are not disabled in posix mode (when they have such a thing),
That is allowed by POSIX. The shell's posix mode is generally to alter
behaviour where we are deliberately doing something different to what
POSIX says we should (or should not) do (or in at least one case,
"previously said"). If anything were to ever change wrt the way we have
RANDOM implemented, it would not depend upon posix mode (-o posix) - or not
unless something very odd happens, and POSIX decides to specify that RANDOM
must be implemented, but in a way that's different to the way we prefer to
have it work.
Home |
Main Index |
Thread Index |
Old Index