You are not logged in.

#1 2010-12-11 08:23:26

modulation
Member
Registered: 2010-02-27
Posts: 6

[solved] Question about Quotes in Shell-Script

I searched for a way to rename my music album folders strictly to the format '<artist> - <album> (<year>)'. I couldn't archieve this with KRename and didn't find an alternative way so i tried to script it. It's really bad i know, but it works for me. I usually use it to rename a bunch of folders in a zsh for loop 'for i in *; dirn $i | tee -a rename.sh'

The Problem now is some albums have " Quotes in it so the Script fails (Line 56).
http://pastebin.com/rePQev61

Maybe someone here can enlighten me how to get folders like these right in the script:
David Bowie - "Heroes" (1977)
Portugal. The Man - Waiter: "You Vultures!" (2006)
The Crickets - The "Chirping" Crickets (2004)
The Long Blondes - "Couples" (2008)

Last edited by modulation (2010-12-11 09:05:49)

Offline

#2 2010-12-11 08:44:18

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

Re: [solved] Question about Quotes in Shell-Script

You just need to escape the evil chars, otherwise your shell will happily munch
them away.

Something like;

s/([;<>\n~\s=\*\|`&\$!#\(\)\[\]\{\}:'"])/\\$1/g

Also, whitespace is evil.

prename 's/\s+/_/g' *

Offline

#3 2010-12-11 08:52:00

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [solved] Question about Quotes in Shell-Script

http://www.grymoire.com/Unix/Quote.html

Removing spaces from filenames: https://bbs.archlinux.org/viewtopic.php … 48#p789148

Last edited by karol (2010-12-11 08:55:39)

Offline

#4 2010-12-11 08:55:02

modulation
Member
Registered: 2010-02-27
Posts: 6

Re: [solved] Question about Quotes in Shell-Script

I'm not sure i get this. $newdir is the corrected name for the album folder. I already strip invalid chars in line 47 (sed -e 's/[|\<>%?^:*\/]/_/g'). But i've trouble with the output of the rename command.

I'd like it to output something like:
mv 'crinckets_the_chiping' 'The Crickets - The "Chirping" Crickets (2004)'
so that the newdir really contains the "-Quotes.

Offline

#5 2010-12-11 09:07:28

modulation
Member
Registered: 2010-02-27
Posts: 6

Re: [solved] Question about Quotes in Shell-Script

Thank you all, i finally got it right. I found the right escaping in the UNIX SHELL Quote Tutorial.

print "mv -vi \'"$olddir"\' \'"$newdir"\'"

ugly but works. smile

Offline

Board footer

Powered by FluxBB