Created
September 19, 2012 20:48
-
-
Save jesseadams/3752157 to your computer and use it in GitHub Desktop.
Useful bash scripts for handling cross platform support
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 | |
function determine_platform(){ | |
local platform_raw=`uname -s | tr "[A-Z]" "[a-z]"` | |
case $platform_raw in | |
"linux") platform='linux';; | |
"darwin") platform='mac';; | |
"freebsd") platform='freebsd';; | |
cygwin*) platform='windows';; | |
"sunos") platform='solaris';; | |
*) platform='unknown' | |
echo "Unknown Platform: $platform_raw" | |
;; | |
esac | |
} | |
determine_platform | |
echo $platform |
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 | |
function platform_exec(){ | |
if [ "$platform" == "windows" ]; then | |
"$@" | |
else | |
sudo "$@" | |
fi | |
} | |
# Instead of sudo - cygwin doesn't have sudo | |
platform_exec netstat -tpan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment