OSTYPE
variable stores the value of the operating system type.
1echo $OSTYPE
linux-gnu # Ubuntu
zsh
and bash
values differ a bit.
$ echo $OSTYPE
darwin18
% echo $OSTYPE
darwin18.0
You can use a glob to account for the inconsistency
if [[ $OSTYPE == darwin* ]]; then
alias flushdns='sudo dscacheutil -flushcache'
fi
Another code snippet from the virualmin install script
1remove_virtualmin_release () {
2 # shellcheck disable=SC2154
3 case "$os_type" in
4 "fedora" | "centos" | "rhel" | "amazon" )
5 run_ok "rpm -e virtualmin-release" "Removing virtualmin-release"
6 ;;
7 "debian" | "ubuntu" )
8 grep -v "virtualmin" /etc/apt/sources.list > "$tempdir"/sources.list
9 mv "$tempdir"/sources.list /etc/apt/sources.list
10 ;;
11 esac
12}
-s
prints the kernel name
Linux # Ubuntu