JoeFootball wrote: ⤴Thu May 24, 2018 1:09 pm
Perhaps you're looking to use the
$RANDOM
variable? More information
here.
Joe
The problem is not that I used the
RANDOM
variable incorrectly. As you can see in the output of
shellcheck
, I used it right:
The problem is that if I ran that line with another shell like
Sh
it would not work because
RANDOM
is not supported by
Sh
.
rene wrote: ⤴Thu May 24, 2018 4:37 pm
Kyowash wrote: ⤴Thu May 24, 2018 1:05 pm
And this surprised me because
RANDOM
is mentioned
here.
I only see it mentioned in in section 8.1? There it's introduced by
It is unwise to conflict with certain variables that are frequently exported by widely used command interpreters and applications:
which is seemingly to say that indeed it's not standardised; the standard warns that you might want to avoid using a so named variable given that it's "frequently exported by widely used command interpreters". The following sections 8.2 and 8.3 -- and assumedly more sections scattered around the specifications -- list actually by the standard itself defined/mandated variables.
Yeah, that line misled me so that I thought that list was formed by standard environment variables. My bad!
So the variables supported by POSIX are just those found in section 8.2 and 8.3? That's a quite reduced list compared to the one I thought that was the correct one. Not even
USER
is found there. And I'm again surprised because I made another script called
check-root-posix.sh
with this content:
Code: Select all
#!/bin/bash
if [ "$USER" = "root" ]
then
echo "User is root."
fi
And
shellcheck -s sh check-root-posix.sh
didn't complaint about it. I'm so confused right now.