[Gllug] More grep stuff

ccooke ccooke-gllug at gkhs.net
Sat Sep 11 07:50:57 UTC 2004


On Fri, Sep 10, 2004 at 09:23:18PM +0100, Dylan wrote:
> Hi All,
> 
> In my quest to extract tag info from ogg files, I have encountered 
> another problem...
> 
> oggenc allows multiple comment arguments, so I figured I would:
> 
> for comment in `ogginfo <file> | grep =
> do
>   comments="-c \"comment\" "$comments
>   done

'for' really isn't the best tool for this. It inherently does word
splitting, so you'd have to paste the lines back together. Try this:

ogginfo "$file" | grep "=" | {

	while read line
	do
		comments="-c \"$comment\" $comments"
	done

	# ... whatever you do with $comments
}

(Bash is annoying in that it runs while loops with pipes in a subshell,
so any variable changes don't affect the outside of the loop. The {}s in
this make the whole block execute in a subshell, instead - and the while
within the {}s executes normally.)

-- 
Charles Cooke, Sysadmin
Say it with flowers, send a triffid.
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list