I'm having trouble understanding whether I can use wildcard globbing in an if statement in fish. This switch/case works as expected:
# correctly echos macOS on macOS
switch "$OSTYPE"
case 'darwin*'
echo 'macOS'
case '*'
echo 'not macOS'
end
However, I cannot get an if statement version of the same thing to work.
# doesn't work - prints 'not macOS' on macOS
if [ "$OSTYPE" = 'darwin*' ]
echo 'macOS'
else
echo 'not macOS'
end
In zsh/bash you can do something like this:
[[ $OSTYPE == darwin* ]] && echo 'macOS' || echo 'not macOS'
Or, more verbosely,
if [[ $OSTYPE == darwin* ]]
then echo 'macOS'
else echo 'not macOS'
fi
My question is, does fish support wildcard globbing against a variable in if
statements? Am I doing this wrong? I cannot find an example in the fish docs that tells me either way.
NOTE: I'm not asking about checking $OSTYPE
in fish. I know there are better ways to do that. My question is limited strictly to whether it is possible to do wildcard globbing in an if
statement in fish.