[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: multiline output variables.
From: |
Stepan Kasal |
Subject: |
Re: multiline output variables. |
Date: |
Tue, 18 Jan 2005 10:46:02 +0100 |
User-agent: |
Mutt/1.4.1i |
Hello Dan and Noah,
I think the following idea is execllent:
On Mon, Jan 17, 2005 at 01:37:03PM -0800, Noah Misch wrote:
> If you wanted to avoid excluding any delimiter, you do something like this:
>
> for ac_var in var1 var2 ... varN
> do
> eval "case \$$ac_var in
> *'
> '*) filter=' | sed '\\''\$q;s/\$/\\\\/'\\' ;;
> *) filter= ;;
> esac"
>
> eval echo \"s,@$ac_var@,\$$ac_var,\;t t\" $filter
> done | existing_cleanup_seds
The code still isn't perfectly correct, though: what if a one line value
happens to end with a backslash? How can you distinguish it from a
multiline value.
And I would use a more readable way to implement it:
for ac_var in var1 var2 ... varN
do
eval ac_val="\"\$$ac_var\""
case $ac_val in
*'
'*) echo "@address@hidden" | sed ...encode... ;;
*) echo "address@hidden"
esac
done | sed ...
The "encode" sed program would take care to encode things properly,
for example 's/\\/\\x/g;$q;s/$/\\/' .
(The main point is that we have to escape real backslashes somehow.)
The post-processing program would recognize lines starting with @,
and decode them, for example:
/^@/!b ok
s/^@//
:loop
N
/\\$/b loop
s/\\x/\\/g
:ok
s/[\\\\&,]/\\\\&/g
s/address@hidden@/s,@&,/
s/$/,;t t/
Thanks to Noah's idea, the value can be any string, yet the performance
is fine.
I'm looking forward to see your code, Dan.
Have a nice day,
Stepan Kasal
- multiline output variables., Dan Manthey, 2005/01/13
- Re: multiline output variables., Noah Misch, 2005/01/14
- Re: multiline output variables., Stepan Kasal, 2005/01/17
- Re: multiline output variables., Dan Manthey, 2005/01/17
- Re: multiline output variables., Noah Misch, 2005/01/17
- Re: multiline output variables.,
Stepan Kasal <=
- Re: multiline output variables., Dan Manthey, 2005/01/24
- Re: multiline output variables., Stepan Kasal, 2005/01/25
- Re: multiline output variables., Dan Manthey, 2005/01/25
- Re: multiline output variables., Stepan Kasal, 2005/01/27
- Re: multiline output variables., Stepan Kasal, 2005/01/28
- Re: multiline output variables., Ralf Wildenhues, 2005/01/28
- Re: multiline output variables., Stepan Kasal, 2005/01/28
- Re: multiline output variables., Paul Eggert, 2005/01/28
- Re: multiline output variables., Dan Manthey, 2005/01/25
- Re: multiline output variables., Ralf Wildenhues, 2005/01/26