[Gllug] More on that bash script

Russell Howe rhowe at siksai.co.uk
Sun Apr 10 01:16:16 UTC 2005


On Sat, Apr 09, 2005 at 08:12:15PM +0100, Dylan wrote:
> On Saturday 09 Apr 2005 17:12 pm, Russell Howe wrote:
> > On Sat, Apr 09, 2005 at 04:21:57PM +0100, Dylan wrote:
> > So I guess you want something like:
> >
> > artist="${tag///-}"
> 
> Unfortunately not - with and without quotes, and using three or four "/" 
> the tag remains unchanged. What we had both forgotten tho was to escape 
> the middle "/"!

Ah, yes, it would seem so :)

> >Note that the quotes are critically important from a security
> >standpoint.
> 
> Are they, it doesn't work with them - only without:
> 
> ARTIST=${ARTIST/\//-}
> 
> gives the required result.

Seems to work with the quotes here, however:

[rhowe at xiao] ~ $ echo "$FOO"
ARTIST=BoA/M-Flo
[rhowe at xiao] ~ $ echo "${FOO//\//-}"
ARTIST=BoA-M-Flo

I'm trying to come up with a test case for the quotes being needed for
security reasons, but can't seem to work one out :)

Not quoting variables properly in shell scripts certainly causes
breakage when dealing with filenames containing things like spaces,
however:

[rhowe at xiao] ~ $ export FOO="BoA/M-Flo - The Love Bug.mp3"
[rhowe at xiao] ~ $ ls "$FOO"
ls: BoA/M-Flo - The Love Bug.mp3: No such file or directory
[rhowe at xiao] ~ $ ls $FOO
ls: BoA/M-Flo: No such file or directory
ls: -: No such file or directory
ls: The: No such file or directory
ls: Love: No such file or directory
ls: Bug.mp3: No such file or directory

I have a script which I use to file away MP3s into a directory
heirarchy, if you're interested. It's in bash.

-- 
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