作者: ackcheng 時間: 2009-1-2 00:52 標題: Shell Script
I am trying to write a shell script that covert all the music file in a folder to use the following format. Tract 01.wav....... Would the following script work?
makedir /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
mv "05*.wav" /music_ram/Track 05.wav
mv "06*.wav" /music_ram/Track 06.wav
mv "07*.wav" /music_ram/Track 07.wav
mv "08*.wav" /music_ram/Track 08.wav
mv "09*.wav" /music_ram/Track 09.wav
mv "10*.wav" /music_ram/Track 10.wav
mv "11*.wav" /music_ram/Track 11.wav
mv "12*.wav" /music_ram/Track 12.wav
mv "13*.wav" /music_ram/Track 13.wav
mv "14*.wav" /music_ram/Track 14.wav
mv "15*.wav" /music_ram/Track 15.wav
mv "16*.wav" /music_ram/Track 16.wav
mv "17*.wav" /music_ram/Track 17.wav
mv "18*.wav" /music_ram/Track 18.wav
mv "19*.wav" /music_ram/Track 19.wav
mv "20*.wav" /music_ram/Track 20.wav
作者: Gundamdriver 時間: 2009-1-2 00:57
1. makedir? mkdir?
2. Why create directory under / (root) directory?
3. You may want to cd (change directory) to the directory where *.WAV are placed...
I don't know what does it mean by mounting none to a directory, so I leave it to other members...

作者: sunlite 時間: 2009-1-2 10:32
why not try it by using "cp" instead of "mv"?
作者: foobar 時間: 2009-1-2 12:47
原帖由 ackcheng 於 2009-1-2 00:52 發表
I am trying to write a shell script that covert all the music file in a folder to use the following format. Tract 01.wav....... Would the following script work?
makedir /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
我諗有 D 小問題令你個 script 未必 work 喎
首先有版友講o左 makedir 應該係 mkdir
跟住句 mount command 個 -o -size=800m 應該係 -o size=800m
然後就係 D mv commands, 你係想 move "Track 01.wav", "Track 02.wav" 等等入去個 directory 入面? 你句 mv command 個 source 寫 "01*.wav", 咁應該唔會 match 到用 Track 開頭o既 file 名
mv Track*.wav /music_ram/
就 OK
最後都係提一句, 你 move 落去個 directory reboot 完就會 clear o左, 你 move 之前最好先 make sure D file 係用完就洗得
作者: corvus 時間: 2009-1-2 14:12
個script初頭最好有個if. 假如個directory唔係度先再mkdir.
作者: little_keung 時間: 2009-1-2 15:46
原帖由 ackcheng 於 2009-1-2 00:52 發表
I am trying to write a shell script that covert all the music file in a folder to use the following format. Tract 01.wav....... Would the following script work?
makedir /music_ram
mount -t tmpfs -o - ...
Do you know the different of "01*.wav" ( double quotation mark ) and 01*.wav ( no quotation mark ) ??
作者: little_keung 時間: 2009-1-2 15:49
It could be a little bit better, but I can't see a big difference in terms of performance or neatness.
"mkdir" itself will check on its own, right ??
作者: corvus 時間: 2009-1-2 16:18 標題: 回覆 7# 的帖子
You don't want any unnecessary message in the sysout (or redirected logfile).
mkdir: cannot create directory `test': File exists
作者: foobar 時間: 2009-1-2 17:19
原帖由 little_keung 於 2009-1-2 15:46 發表
Do you know the different of "01*.wav" ( double quotation mark ) and 01*.wav ( no quotation mark ) ??
Wow, 你唔講我都冇為意添
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 唔到 ?
作者: little_keung 時間: 2009-1-2 17:47
原帖由 corvus 於 2009-1-2 16:18 發表
You don't want any unnecessary message in the sysout (or redirected logfile).
I agree it is a good practice, but I don't agree it is an important step to solve the current issue.
作者: little_keung 時間: 2009-1-2 17:49
原帖由 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.
作者: foobar 時間: 2009-1-2 18:41
原帖由 little_keung 於 2009-1-2 17:49 發表
Case 1 & 2 is quite obvious, but case 3 may be shell dependent.
作者: 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_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?
作者: little_keung 時間: 2009-1-3 17:08
原帖由 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 編輯 ]
作者: ackcheng 時間: 2009-1-5 16:13
Thanks.
I need some time to digest your code.

