I am using the following code to test if a function exists but Bash gives the following diagnostic:
[: =: unary operator expected
The code is:
if [ $(type -t deactivate) != function ];
How should this be expressed in a shell script independent manner?
It is in general not possible to use the same syntax for csh
and bash
.
As for the error in your script: it is probably caused by the fact the type -t deactivate
does not produce output. Proper quoting will solve that issue:
if [ "$(type -t deactivate)" != "function" ] ; then