Last active
November 20, 2017 10:17
-
-
Save gousiosg/d003e0b18a2ec33407b29f23befce810 to your computer and use it in GitHub Desktop.
How compatible is your Unix with the original one?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
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.