Here is what I'm trying to do in one of my bash scripts.
If SERVER_ENV is not PROD or TEST, the script must exit.
check-server-env() {
local SERVER_ENV="$1"
if ! [[ "$SERVER_ENV"^^ =~ ^(TEST|PROD)$ ]]; then
error "$(highlight "$SERVER_ENV")" " does not exist."
echo "Exiting script..."
echo ""
exit 0
fi
}
I call script.sh TEST
SERVER_ENV=$1
check-server-env $SERVER_ENV
Here is how I'm calling. And it's not working. What am I doing wrong?
if [ "$SERVER_ENV" != TEST ] && [ "$SERVER_ENV" != PROD ]; then ...."${SERVER_ENV^^}"(note the{and}).regextag removal rationale. If OP wants a regex help what's wrong with having it in question?