[Gllug] Variable substitutuion in bash

Dylan dylan at dylan.me.uk
Sat Sep 11 18:42:04 UTC 2004


Hi all,

Still beavering away on this script - and learning much into the bargain 
which is a Very Good Thing in my book.

Anyway, Using Stuart's script fragment (altered for my script):

   comments=""
    for line in `ogginfo "$src_file" | grep = |cut -f2|\
                    sed -e 's/^/-c \"&/' -e 's/$/\"/'`
    do
      comments="$comments $line"
    done
 

 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"
music at audio:/media/music/test>

So far so good. The command works correctly when the list is explicitly 
given (excuse wrapping):

music at audio:/media/music/test> oggenc adj.wav -q 0 -n 
"./processed/10cc.ogg" -c "ALBUM=Milestones"-c "ARTIST=10cc" -c 
"DESCRIPTION=" -c "GENRE=" -c "KDE-ENCODER=kio_audiocd" -c "TITLE=Im 
Not In Love" -c "TRACKNUMBER=7"
Opening with wav module: WAV file reader
Encoding "adj.wav" to
         "./processed/10cc.ogg"
at quality 0.00
        [  1.0%] [ 3m44s remaining] \
music at audio:/media/music/test>

But:

music at audio:/media/music/test> oggenc adj.wav -q 0 -o 
"./processed/10cc.ogg" $comments
ERROR: Multiple input files with specified output filename: suggest 
using -n
music at audio:/media/music/test>

I've established that this is because when the list of -c options is 
given in a variable, oggenc is erroneously interpreting Not, In and 
Love" as filenames, even though the string is quoted. So - question 1: 
Why does this happen with variable substitution and not when given 
literally?

Also, when a string of -c options is given in the variable, the quotes 
get incorporated into the file tag:

music at audio:/media/music/test> ogginfo ./processed/10.ogg
Processing file "./processed/10.ogg"...

New logical stream (#1, serial: 79060d0f): type vorbis
Vorbis headers parsed for stream 1, information follows...
Version: 0
Vendor: Xiph.Org libVorbis I 20030909 (1.0.1)
Channels: 2
Rate: 44100

Nominal bitrate: 64.001000 kb/s
Upper bitrate not set
Lower bitrate not set
User comments section follows...
        "ALBUM=Milestones"
        "ARTIST=10cc"
        "DESCRIPTION="
        "GENRE="
        "KDE-ENCODER=kio_audiocd"
        "TITLE=ImNotInLove"
        "TRACKNUMBER=7"
Warning: EOS not set on stream 1
Vorbis stream 1:
        Total data length: 37967 bytes
        Playback length: 0m:05s
        Average bitrate: 57.450751 kbps
music at audio:/media/music/test>

But not when they are explicitly in the cmd. This is clearly related, 
but I don't know enough about the mechanics of quoting and variable 
substitution to work out what is wrong...

As usual, any suggestions are most gratefully received.

Cheers
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