To make it short, doing something like:
-bash$ function tt
{
echo $0;
}
-bash$ tt
$0
will return -bash
, but how to get the function name called, i.e. tt
in this example instead?
bashfunctionshell-script
To make it short, doing something like:
-bash$ function tt
{
echo $0;
}
-bash$ tt
$0
will return -bash
, but how to get the function name called, i.e. tt
in this example instead?
Best Answer
In
bash
, use FUNCNAME array:With some
ksh
implementations:In
ksh93
:From
ksh93d
and above, you can also use$0
inside function to get the function name, but you must define function usingfunction name { ...; }
form.In
zsh
, you can usefuncstack
array:or
$0
inside function.In
fish
: