[问题]如何调用数组??
- solcomo
- 帖子: 2838
- 注册时间: 2007-04-25 13:12
- woohaha
- 帖子: 133
- 注册时间: 2007-07-17 22:09
- 来自: 广东
我把整个脚本给大家看看,帮我改改吧。现在就是文件名空格问题和歌曲tag问题没搞好。
运行情况
代码: 全选
#!/bin/bash
#This script is used for converting single APE/FLAC to multi FLACs.
#woohaha 08-08-24
declare -i count=0
declare -a filenames
if [ "$1" == "" ]; then
#若脚本后面带有文件则执行文件,否则列出所有cue文件
for filename in `ls *.cue`; do
filenames[$count]=$filename
echo "[$count]: ${filenames[$count]}"
count=$count+1
done
#列出所有cue文件
echo "Which File Would You Like To Convert?"
echo "Input Number to Select(Press Q to Exit)"
read n
if [ "$n" == "q" ] || [ "$n" == "Q" ]; then
exit 1
fi
#若输入Q则退出
cuename=${filenames[$n]}
else cuename=$1
fi
convname=${cuename}_bak
iconv -f GBK -t UTF-8 $cuename -o $convname
#为了不破坏原本的cue文件,转换编码输出成另外一个文件
Nameline=`grep FILE $convname`
#在cue文件内找到含有ape/flac文件名的行
Nametail=${Nameline#*\"}
Name=${Nametail%\"*}
#取出文件名
mkdir ${Name%.*}
cd ${Name%.*}
#创建一个与音乐文件同名的目录
shntool split -f “../$convname“ -t''%n.%t'' -o flac ”../${Name}“
#分割文件(这是核心)
rm ../$convname
#删除转换成utf-8编码的cue文件
exit 0
代码: 全选
woohaha@woohaha-laptop:~/test$ ./Spilt-024.sh
[0]: asdfg.cue
[1]: cvcvcx.cue
[2]: lskdf
[3]: j
[4]: skdl
[5]: sldkfjkl.cue
[6]: lskdfjskdl
[7]: sldkfjkl.cue
[8]: sadfasdfasd.cue
[9]: sad
[10]: fasdf.cue
[11]: zxcvxcv.cue
Which File Would You Like To Convert?
Input Number to Select(Press Q to Exit)
q
woohaha@woohaha-laptop:~/test$ ll *.cue
-rw-r--r-- 1 woohaha woohaha 0 2008-08-24 01:31 asdfg.cue
-rw-r--r-- 1 woohaha woohaha 0 2008-08-24 01:31 cvcvcx.cue
-rw-r--r-- 1 woohaha woohaha 0 2008-08-24 15:23 lskdf j skdl sldkfjkl.cue
-rw-r--r-- 1 woohaha woohaha 0 2008-08-24 15:23 lskdfjskdl sldkfjkl.cue
-rw-r--r-- 1 woohaha woohaha 0 2008-08-24 01:31 sadfasdfasd.cue
-rw-r--r-- 1 woohaha woohaha 0 2008-08-24 15:22 sad fasdf.cue
-rw-r--r-- 1 woohaha woohaha 0 2008-08-24 01:31 zxcvxcv.cue