#!/bin/bash

set -e

_=`which sw_vers`
if [ 0 -eq $? ] # macOS
then
	name=`sw_vers -productName`
else
	name=`uname -s`
fi
echo "${name}" | awk '{ gsub(" ", "") ; print tolower($0) }'

#!/bin/bash

_=`which sw_vers`
if [ 0 -eq $? ] # macOS
then
	set -e
	name=`sw_vers -productName`
else
	set -e
	name=`uname -s`
fi
echo "${name}" | awk '{ gsub(" ", "") ; print tolower($0) }'

Call set -e only after checking whether sw_vers is available
Call set -e only after checking whether sw_vers is available
