Skip to content

Instantly share code, notes, and snippets.

@jesseadams
Created September 19, 2012 20:48
Show Gist options
  • Save jesseadams/3752157 to your computer and use it in GitHub Desktop.
Save jesseadams/3752157 to your computer and use it in GitHub Desktop.
Useful bash scripts for handling cross platform support
#!/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
#!/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