Having some issues checking whether the hostname of the current host matches a whitelist and running an if statement that only runs if the host matches the whitelist and an application is installed. Here's what I have.. where am I going wrong? It's always returning exit 1
no matter what.
#!/bin/bash
WHITELIST=(host1 host2 host3)
printf -- '%s\n' "${WHITELIST[@]}" | grep $HOSTNAME
if [ -e "/Applications/myapp.app" ] && [ $? = 1 ];
then
echo "myapp exists and hostname doesn't match whitelist"
exit 0
else
echo "myapp doesn't exist or hostname matches whitelist"
exit 1
fi