Last active
March 31, 2022 09:23
-
-
Save aamnah/f5b3dbbdb3721cd907879f943cb6c30a to your computer and use it in GitHub Desktop.
Check operating system inside a bash script and change commands
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
# Flush DNS cache | |
if [[ $OSTYPE == darwin* ]]; then | |
# works on macOS | |
alias flushdns='sudo dscacheutil -flushcache' | |
elif [[ $OSTYPE == linux* ]]; then | |
# works on Ubuntu 18.04+ | |
alias flushdns='sudo systemd-resolve --flush-caches' | |
fi |
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
UNAME=$(uname -s | tr '[:upper:]' '[:lower:]') | |
# example if/esle statement 1 | |
if [[ $UNAME = darwin ]]; then | |
echo "You are on macOS" | |
elif [[ $UNAME = linux ]]; then | |
echo "You are on Linux" | |
fi | |
# example if/esle statement 2 | |
[[ $UNAME = darwin ]] && echo "You are on macOS" || echo "You are on macOS" | |
# example if/esle statement 3 | |
if [[ $UNAME = darwin ]]; then echo "You are on macOS"; else echo "You are on macOS"; fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment