I have this bash code that checks if the OS is Linux or Mac, and I use the function isWhat to be invoked from other functions.
function isWhat
{
if [ `uname` == $1 ];
then
return 1
else
return 0
fi
}
function isLinux
{
return isWhat("Linux")
}
function isMac
{
return isWhat("Darwin")
}
However, I got these errors:
/functions.sh: line 13: syntax error near unexpected token `('
/functions.sh: line 13: ` return isWhat("Linux")'
runme.sh: line 7: isMac: command not found
What might be wrong?
functionkeyword at all; it makes your script incompatible with POSIX sh for no good reason.isWhat() {is enough to start a function, and using that form retains compatibility with pure POSIX shells.==isn't guaranteed to work inside[ ]by the POSIX standard (the standardized string comparison operator is=, not==). Try running through shellcheck.net for an automated check for the quoting errors..bash, not.sh.