[Gllug] Variable substitutuion in bash

Dylan dylan at dylan.me.uk
Sat Sep 11 21:01:13 UTC 2004


On Saturday 11 Sep 2004 20:10 pm, Russell Howe wrote:
> On Sat, Sep 11, 2004 at 07:42:04PM +0100, Dylan wrote:
> >  I have a variable $comments which contains a list of comment
> > options for oggenc, e.g.:
> >
> > music at audio:/media/music/test> echo $comments
> > -c "ALBUM=Milestones" -c "ARTIST=10cc" -c "DESCRIPTION=" -c
> > "GENRE=" -c "KDE-ENCODER=kio_audiocd" -c "TITLE=Im Not In Love" -c
> > "TRACKNUMBER=7"
>
> Why not use bash's array variables for this?

Because this is my first script beyond a simple list of fixed commands, 
and I didn't know that arrays could be used like this...

<SNIP script>

Yes, that will build a list of cmd line options. I've tried using an 
array since I sent the OP and the same problem occurs. It is definitely 
related to having quotes (" or ') around strings in the variable. I've 
tried using:

$var, ${var}, "$var" and "${var}"

but always the quotes act as literal characters. When I issue:

oggenc file.wav -c "TAG=value with spaces"

I get an ogg file with the tag TAG=value with spaces

When I set a variable to "TAG=value with spaces" and do:

oggenc file.wav -c $var

I get an ogg with the tag "TAG=value

and then cannot open file errors for file 'with' and 'spaces'.

It doesn't matter what quotes are used.

Dylan

-- 
"I see your Schwartz is as big as mine" 
                                  -Dark Helmet
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list