[Top][All Lists]

[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
        eval ac_val="\"\$$ac_var\""
        case $ac_val in
'*)             echo "@address@hidden" | sed ...encode... ;;
        *)      echo "address@hidden"
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
/\\$/b loop
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

reply via email to

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