[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: consistency probs var & function re-use
From: |
L A Walsh |
Subject: |
Re: consistency probs var & function re-use |
Date: |
Sun, 11 Jun 2017 15:51:26 -0700 |
User-agent: |
Thunderbird |
Charles Daffern wrote:
First problem: If you are assigning a string to a variable,
you need to put quotes around the string. That shows that "-p"
doesn't insert newlines:
> x="$'foo\nbar'"
> declare -p x
declare -- x="\$'foo\\nbar'"
You do not have any newlines in that string, so of course the
demonstration with -p will show no newlines.
Right. you should be addressing your comment to 'Greg Wooledge',
who said:
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"
------
I was pointing out that the reason 'declare' used a newline, was that he
had not quoted the input to 'x', which is expanded to a newline
before it is assigned to 'x'.
Or did you miss that post?
What are you trying to do?
Read var & func defs via a 'read' of 1 line.
In your variable "x" above, you have encoded the string in a format
which contains no raw newlines and which can be "eval"ed to produce the
original contents.
Why don't you encode the function the same way?
I didn't encode the newline above, Greg did.
I used a format with NO newlines:
hh(){ echo "hi"; }
which gets printed out as:
declare -f hh
hh ()
{
echo "hi"
}
----
I.e. it wasn't that I wanted to embed newlines in the function, but that
I wanted it to print out the same way it was input.
- Re: consistency probs var & function re-use, (continued)
- 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
- Re: consistency probs var & function re-use, L A Walsh, 2017/06/11
- Re: consistency probs var & function re-use, Charles Daffern, 2017/06/10
- Re: consistency probs var & function re-use,
L A Walsh <=
- Re: consistency probs var & function re-use, Greg Wooledge, 2017/06/13