Skip to content

Instantly share code, notes, and snippets.

@gousiosg
Last active November 20, 2017 10:17
Show Gist options
  • 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

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