On Wed, Aug 23, 2017 at 03:23:50PM -0400, Greg Wooledge wrote: > On Wed, Aug 23, 2017 at 01:16:56PM -0600, Aaron Toponce wrote: > > Three POSIX-compliant shell functions that rely on no extra utilities > > shuff () { > > if [ $(command -v shuf) ] > > Needs quotes.
Good catch. > > shuffle -f /dev/stdin -p "$1" > > /dev/stdin is not POSIX-compliant. Interesting. I was not aware of that. > > else > > awk 'BEGIN{ > > "od -tu4 -N4 -A n /dev/urandom" | getline > > /dev/urandom is not POSIX-compliant. Then again, I don't believe there > is *any* POSIX-compliant source of randomness available to shell scripts > other than awk's srand and rand. > > Emulating /dev/urandom in awk is left as an exercise. ;-) > > > [ $(uname) = "SunOS" ] && FILE="/usr/dict/words" || > > FILE="/usr/share/dict/words" > > It'd be better to list all the possible places the dict file may exist, > and iterate through them until you find it, regardless of uname. Agreed. I tested this on the BSDs, GNU/Linux, and Solaris/OmniOS/SmartOS. I don't have access to HP-UX, IBM AIX, True64, and some of the other Unices. Is Plan9 still a thing? > Also, don't use all-caps shell variable names. All-caps names are > reserved for special internal variables, and environment variables. I've gone back and forth on this. I'd be interested to see a standard specification on this, if such exists. It seems convention that uppercase is used more frequently for shell variables than lowercase. I've tended to lean on uppercase more frequently as a result. Just so long as it doesn't clash with existing variables, I don't see the reason not to. -- . o . o . o . . o o . . . o . . . o . o o o . o . o o . . o o o o . o . . o o o o . o o o
signature.asc
Description: PGP signature