2014-04-08 110 views
0

我有很多flac專輯,每個專輯都放在一個文件中,我想將它分成多個軌道。我可以保證每個文件夾只有一個flac文件,其中一個提示文件具有相同的名稱。cd命令在shell腳本中無法正常工作

我寫道:

#!/bin/sh 
IFS=$'\n' 
current=`pwd` 
for d in `find . -name *.cue -print0 | xargs -0 -n1 dirname | sort --unique` 
do 
    cd \""$d"\" 
    f=`ls *.cue` 
    cuebreakpoints *.cue | shnsplit flac *.flac 
    cuetag *.cue split*.flac 
    rm ${f%.cue}.* 
    cd \""$current"\" 
done 
unset IFS 

由於find命令不逃避的文件名,我改變了IFS到換行符。當我執行腳本時,它在兩個cd行中均失敗,表示提供的路由不存在。

例如,假設該文件結構:

> Downloads 
    split.sh 
    > Music 
     > FLAC 
      > Goa Trance 
       > Others 
        > (1997) Test Label - Album Name - Subtitle Of The Album 
         album test.flac 
         album test.cue 

當我執行腳本拋出兩個錯誤(和其他錯誤,從一個事實,即不更改目錄導出):

./split.sh: line 6: cd: "./Music/FLAC/Goa Trance/Others/(1997) Test Label - Album Name - Subtitle Of The Album": No such file or directory 
... 
./split.sh: line 11: cd: "/Users/robotFive/Downloads": No such file or directory 

但是,如果我執行完全這一切的作品:

cd "./Music/FLAC/Goa Trance/Others/(1997) Test Label - Album Name - Subtitle Of The Album" 
cd "/Users/robotFive/Downloads" 

你知道什麼可能是hap pening?

謝謝。

回答

1

我認爲這是一個逃了,變化:

cd \""$d"\" 

到:

cd "$d" 
+0

謝謝。我做錯了我的測試,並得出結論,逃脫的報價是必要的。 – davidgnin

+0

我知道,轉義空格在shell腳本中是個婊子... – Mathias