In Bash I can use $(type -t function_name) = "function" to check if the function by name function_name exists or not in a sourced file which is sourced using source file_name command. I'm trying to achieve the same in ksh where the source command equivalent is .. But I'm stuck with type -t syntax for which I'm getting the below error in ksh.
abc.sh in Bash
source def.sh
if [ "$(type -t foo)" != "function" ]; then
echo "function foo exists"
fi
abc.sh in Korn
. def.sh
if [ "$(type -t foo)" != "function" ]; then
echo "function foo exists"
fi
Error in Korn shell
./abc.sh[4]: whence: -t: unknown option
ksh version
echo $KSH_VERSION
@(#)PD KSH v5.2.14 99/07/13.2
type fooprintsfoo is a function. Of course in Bash it also prints the function definition, so you'd have to clean that up or use different commands on the two shells.!=where you mean=?.is the standard sh command supported by all Bourne-like shell, whilesourceis the csh equivalent (also supported by a few shells)..looks files up in$PATHthough if there's no/in their path (and with some shells and in some environments falls back to the current working directory if not found in$PATH; forsourceYMMV). Use. ./def.shif you want to source thedef.shin the current working directory.