help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] read that understands quoting


From: Greg Wooledge
Subject: Re: [Help-bash] read that understands quoting
Date: Mon, 12 Mar 2012 08:23:10 -0400
User-agent: Mutt/1.4.2.3i

On Sat, Mar 10, 2012 at 02:26:28PM -0600, Bill Gradwohl wrote:
> someScript     'this is one field'        thisisanotherfield        'This
> is the last field'
> 
> I get 3 passed parameters. If I read a line from a file with the identical
> parameters, I get 10 fields as the quoting is ignored.

I only know of 3 ways to do this, and 2 of them are crap.

The two that are crap are xargs(1) and eval.  Of these, of course eval
is the crappier, because you have no defense against code injection.
xargs can be made to read Apache-log-file-type input (like your example),
but only if the input is well-formed, with all the quotes matching
up properly.

The third way, and the only one that isn't crap, is to write your own
parsing routine that scans the input string character by character and
tokenizes it.

If your real goal is parsing Microsoft-ish "CSV" files, rather than
Apache log files, then you're going to end up using the third one,
because xargs can't handle embedded escaped quotes.



reply via email to

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