bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

typeset -p & manpage on it are confusing w/rt funcs


From: Linda Walsh
Subject: typeset -p & manpage on it are confusing w/rt funcs
Date: Thu, 06 Jun 2013 15:48:09 -0700
User-agent: Thunderbird


I wanted to test to see if a function was defined and looking at
typeset in the bash man page, I see
typeset ...   The -p option  will
              display the attributes and values of each name.  When -p is used
              with name arguments, additional options are ignored.  When -p is
              supplied  without name arguments, it will display the attributes
              and values of all variables having the attributes  specified  by
              the  additional  options.  If no other options are supplied with
              -p, declare will display the attributes and values of all  shell
              variables.   The  -f  option  will restrict the display to shell
              functions.  The -F option inhibits the display of function defi-
              nitions;
                

ok ... so reading the above, how does "-f" and -F" tie in with
"-p" ??  If I use -f with -p does that limit it to functions only?
Er... what?

If I define local functions and vars:
env -i bash --norc
bash-4.2$ PATH=.:/usr/bin:/bin
bash-4.2$ function fff () { echo "fff_func" ;}
bash-4.2$ aaa=eee
bash-4.2$ typeset -p |grep -P 'aaa|fff'
declare -- aaa="eee"
bash-4.2$ fff
fff_func

So why is 'aaa' displayed but not fff?

doesn't -p display all the names and their attributes?
If I wanted it to only work with functions...

Could I use -f?:

bash-4.2$ typeset -pf
fff ()
{
    echo "fff_func"
}
bash-4.2$ typeset -fp
fff ()
{
    echo "fff_func"
}
---
Nope.  No attributes..
bash-4.2$ export fff
bash-4.2$ typeset -fp
fff ()
{
    echo "fff_func"
}

Still no attributes:
$ typeset -p aaa
declare -- aaa="eee"
bash-4.2$ typeset -p fff
bash: typeset: fff: not found
-- "-p" print "aaa", but doesn't find the function.

But without a name give to "-p"
bash-4.2$ typeset -p |grep -P 'aaa|fff'
declare -- aaa="eee"
declare -x fff
----
In the dump of all, I see that fff is exported.  Why don't
I see it when I specify it by name?
i.e. typeset -p fff:
$ typeset -p fff
bash: typeset: fff: not found

--- Seems like "-p" doesn't work consistently with functions?

Is that something that could be made consistent -- as it is it is
more than a little confusing... especially with the docs talking about
using -f/-F to include/exclude functions when giving names to -p (but it
seems like it doesn't work when you give names to -p, only in the
"no name"case.

I can sorta figure out what I want by looking at the status of typeset -f <func>
and sending the output to /dev/null, but that doesn't address the
confusing behavior or "-p" or how it is documented...???








reply via email to

[Prev in Thread] Current Thread [Next in Thread]