[Gllug] Parsing strings in a shell script

Russell Howe rhowe at wiss.co.uk
Fri Sep 10 16:31:05 UTC 2004


On Fri, Sep 10, 2004 at 10:05:18AM +0100, Richard Jones wrote:
> It's _almost_ possible to do:
> 
> $ eval `ogginfo 01-spandau_ballet__gold.ogg | grep artist`
> $ echo $artist
> Various

No!

> But this fails in the general case where the values contain spaces or
> shell metacharacters:
> 
> $ eval `ogginfo 01-spandau_ballet__gold.ogg | grep '='`
> bash: syntax error near unexpected token `('
> 
> I can't find out the bashness to make it ignore the spaces, brackets
> and so on.  Setting IFS doesn't help ...

That's because you're saying "Read a bash script from the output of this
command and execute it". Not exactly what you want to do with untrusted
input (which is what I assume an OGG tag would be considered to be)

What if someone has a band called "`rm -rf ~`"?

-- 
Russell Howe       | Why be just another cog in the machine,
rhowe at siksai.co.uk | when you can be the spanner in the works?
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list