Skip to content

Instantly share code, notes, and snippets.

@gousiosg
Last active November 20, 2017 10:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gousiosg/d003e0b18a2ec33407b29f23befce810 to your computer and use it in GitHub Desktop.
Save gousiosg/d003e0b18a2ec33407b29f23befce810 to your computer and use it in GitHub Desktop.
How compatible is your Unix with the original one?
#!/usr/bin/env bash
TEMPFILE=/tmp/unixcount
exist=0
notexist=0
echo 0 0 > $TEMPFILE
curl "https://raw.githubusercontent.com/dspinellis/unix-v4man/master/man0/ptxx"|
grep "(I)"|
sed -e 's/.*\"\(.*\)(I).*/\1/'|
sort|
uniq|
while read cmd; do
if hash "$cmd" 2>/dev/null; then
echo "$cmd exists";
exist=$((exist+1))
else
echo "$cmd does not exist"
notexist=$((notexist + 1))
fi
echo $exist $notexist > $TEMPFILE
done
exist=`cat $TEMPFILE|cut -f1 -d ' '`
notexist=`cat $TEMPFILE|cut -f2 -d ' '`
total=$(($exist+$notexist))
perc=`echo "scale=2; $exist / $total * 100"| bc -l`
echo
echo "Your system (`uname -v`) is $perc% UNIX"
unlink $TEMPFILE
@gousiosg
Copy link
Author

gousiosg commented Nov 19, 2017

Running this on various systems:

  • MacOSX 10.12: Your system (Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64) is 70.00% UNIX
  • Debian 8.x: Your system (#1 SMP Debian 3.16.39-1 (2016-12-30)) is 70.00% UNIX
  • Ubuntu 16.04 LTS: Your system (#88-Ubuntu SMP Wed Mar 8 16:34:45 UTC 2017) is 70.00% UNIX (After installing bc by hand)

The list of commands that are missing is exactly the same across all systems!

bas does not exist
catsim does not exist
cdb does not exist
chdir does not exist
cref does not exist
db does not exist
dc does not exist
dsw does not exist
fed does not exist
form does not exist
goto does not exist
if does not exist
merge does not exist
opr does not exist
pfe does not exist
plot does not exist
proof does not exist
rew does not exist
roff does not exist
sno does not exist
speak does not exist
tp does not exist
tss does not exist
typo does not exist

@Inventitech
Copy link

Ha!

Ubuntu 17.10: Your system (#19-Ubuntu SMP Wed Oct 11 18:35:14 UTC 2017) is 71.00% UNIX

But your script has a problem: I have if, and yet it is displayed as non-existent.

@gousiosg
Copy link
Author

Indeed. if is a bash built-in, which hash does not detect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment