3 ms·
$RANDOM isn't actually in POSIX, and /bin/sh might not implement it at all: /tmp$ cat test.sh #!/bin/sh echo $RANDOM $RANDOM $RANDOM /tmp$ ./t
by JoshTriplett 12y ago
$RANDOM isn't actually in POSIX, and /bin/sh might not implement it at all:
/tmp$ cat test.sh
#!/bin/sh
echo $RANDOM $RANDOM $RANDOM
/tmp$ ./test.sh
/tmp$
In a shell that implements it, though, such as bash, you can't override it via the environment. However, it's quite difficult to write privileged shell code if you don't trust the environment, notably $PATH. Too many shell features depend on variables, and shells don't automatically sanitize those.