[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: consistency probs w/ 'readonly -f' & 'export -f
From: |
Greg Wooledge |
Subject: |
Re: consistency probs w/ 'readonly -f' & 'export -f |
Date: |
Fri, 9 Jun 2017 08:25:12 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Thu, Jun 08, 2017 at 03:48:21PM -0700, L A Walsh wrote:
> >Second) What is the official way to list functions w/their
> >flags+definitions
> > in a way reusable as input?
declare -fp funcname
> >Third) How can one print the flags on a single function?
> using> declare -pf <funcname>
Why are you asking if you already know the answer?
> output:
> <funcname> ()
> {
> <content>
> }
> declare -frx <funcname>
Right. There you go.
> >why [is] the "declare [flags] name=value"
> >format ... prevented from working for functions?
I don't know what you mean. A function is not a name=value pair.
Why would you expect the output to have an = sign in it? Or, why
would you expect name=value to create a function?
Are you asking to see the internal serialization syntax that bash uses
when it hacks a function definition into the environment? You can just
dump the raw environment variable if that's what you want.
imadev:~$ export -f sprunge
imadev:~$ env | awk '/_sprunge/{print; getline; print}'
BASH_FUNC_sprunge%%=() { tail -n +1 -- "$@" | curl -F 'sprunge=<-'
http://sprunge.us
}
Is that what you're looking for? Bear in mind, the environment variable
name is dependent on which shellshock patch your version of bash uses.
E.g. in Debian wheezy:
greg@remote:~$ foo() { echo foo; }; export -f foo
greg@remote:~$ env | awk '/_foo/{print; getline; print}'
BASH_FUNC_foo()=() { echo foo
}
This is not meant to be seen by the ordinary end user. It's internal
voodoo.
> Sure seems like it would allow for some better consistency in
> some circumstances, not to mention a more compact function-definition
> form for re-use.
What are you talking about? Consistency between what two things?
Are you allergic to newlines? declare -p uses raw newlines in its output
whenever it feels they are appropriate. Even in ordinary shell variables:
imadev:~$ x=$'foo\nbar'
imadev:~$ declare -p x
declare -- x="foo
bar"
Is that "consistent" enough for you?
Remember, a newline only takes 1 byte of memory.
The output is reusable, but only if you actually use it correctly. E.g.
stuff it into a variable and use eval "$myvar" with the double quotes.
Or redirect it into a file and use source ./myfile.
What are you trying to do? What did you try? What happened? What did
you expect to happen instead?
- consistency probs w/ 'readonly -f' & 'export -f, L A Walsh, 2017/06/08
- Re: consistency probs w/ 'readonly -f' & 'export -f, L A Walsh, 2017/06/08
- Re: consistency probs w/ 'readonly -f' & 'export -f,
Greg Wooledge <=
- Re: consistency probs var & function re-use, L A Walsh, 2017/06/09
- Re: consistency probs var & function re-use, Chris F.A. Johnson, 2017/06/09
- Re: consistency probs var & function re-use, L A Walsh, 2017/06/09
- Re: consistency probs var & function re-use, Chris F.A. Johnson, 2017/06/09
- Re: consistency probs var & function re-use, Chris F.A. Johnson, 2017/06/09
- Re: consistency probs var & function re-use, L A Walsh, 2017/06/11
- Re: consistency probs var & function re-use, L A Walsh, 2017/06/11
- Re: consistency probs var & function re-use, Chet Ramey, 2017/06/11