原帖由 foobar 於 2009-1-2 17:19 發表


Wow, 你唔講我都冇為意添   返而後面個 "Track 01.wav" 應該要 quote

Filename expansion 係容易搞亂, 舉個例, 一個 Folder 入面有三個 File 我當叫 file01.txt, file02.txt, file03.txt:
1) ls -l  file*.txt
2) ls -l "file*.txt"
3) for i in "file*.txt"; do ls -l $i; done
邊個 list 到邊個又 list 唔到 ?  



Case 1 & 2 is quite obvious, but case 3 may be shell dependent.

TOP

原帖由 little_keung 於 2009-1-2 17:49 發表



Case 1 & 2 is quite obvious, but case 3 may be shell dependent.


It is quite interesting that the "file*.txt" in case 2 doesn't get expanded when being passed to ls so it won't match any file, while the "file*.txt" in case 3 will get expanded to a list properly by bash before loop thus giving correct output.

TOP

Thankyou so much for everyones help

I actually wants to replace all music files with
01. Happy song.wav
02. Said song.wav....

to

Track 01.wav
Track 02.wav

Here is the revised script
mkdir /music_ram
mount -t tmpfs -o size=800m none /music_ram

mv "01*.wav" /music_ram/"Track 01.wav"
mv "02*.wav" /music_ram/"Track 02.wav"
mv "03*.wav" /music_ram/"Track 03.wav"
mv "04*.wav" /music_ram/"Track 04.wav"


Looks OK?

TOP

原帖由 ackcheng 於 2009-1-3 01:43 發表
Thankyou so much for everyones help

I actually wants to replace all music files with
01. Happy song.wav
02. Said song.wav....

to

Track 01.wav
Track 02.wav

Here is the revised script
mkdir /music ...


You are still missing from the difference of "01*.wav" and 01*.wav ( simply double quoted and non double quoted )

If you are not very good at handling wildcard, why not use a text editor to help it ?
For example,
Write cp -v "01. love song.wav" "Track 01.wav" instead. ??


Here is my implement of your script.
n=1
for i in *.wav
do
    f=`printf "Track %02d.wav" $n`
    cp -v $i outdir/"$f"
    n=$((n+1))
done

[ 本帖最後由 little_keung 於 2009-1-4 02:12 編輯 ]

TOP

Thanks.

I need some time to digest your code.

TOP