Peng Yu
2018-03-05 17:17:17 UTC
The following example shows that a local function can be defined
within a function. But `type` (as the way that I use it) cannot
distinguish them. Is there a way to tell what functions are local and
what are global?
$ cat main_x1.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
set -v
function cmd {
function cmd1 {
echo xxx
}
type cmd1
cmd1
}
type cmd
cmd
$ ./main_x1.sh
function cmd {
function cmd1 {
echo xxx
}
type cmd1
cmd1
}
type cmd
cmd is a function
cmd ()
{
function cmd1 ()
{
echo xxx
};
type cmd1;
cmd1
}
cmd
cmd1 is a function
cmd1 ()
{
echo xxx
}
xxx
within a function. But `type` (as the way that I use it) cannot
distinguish them. Is there a way to tell what functions are local and
what are global?
$ cat main_x1.sh
#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
set -v
function cmd {
function cmd1 {
echo xxx
}
type cmd1
cmd1
}
type cmd
cmd
$ ./main_x1.sh
function cmd {
function cmd1 {
echo xxx
}
type cmd1
cmd1
}
type cmd
cmd is a function
cmd ()
{
function cmd1 ()
{
echo xxx
};
type cmd1;
cmd1
}
cmd
cmd1 is a function
cmd1 ()
{
echo xxx
}
xxx
--
Regards,
Peng
Regards,
Peng