感谢rq的帮忙,然后根据parameter expansion段中的内容我做了几个测试
首先第一个
apefile=$(ls -tr *.ape)
echo -e $apefile
wavfile=${apefile//ape/wav} # 考虑到可能一串字符之用/%的话只能替换最后一
个 ,事实证明是正确的
echo -e $wavfile
输出如下
Underground 6.0.ape Underground 5.0.ape
Underground 6.0.wav Underground 5.0.wav
第二个用bash内置的*.ape
apefile=*.ape
echo -e $apefile
wavfile=${apefile//ape/wav}
echo -e $wavfile
输出结果如下
Underground 5.0.ape Underground 6.0.ape
*.wav
第三个我写成了
apefile=*.[Aa][Pp][Ee]
echo -e $apefile
wavfile=${apefile//ape/wav}
echo -e $wavfile
输出如下
Underground 5.0.ape Underground 6.0.ape
Underground 5.0.ape Underground 6.0.ape
------------------------------------------------------------------------
在for的循环中则没有问题 ..
for apefile in *.[Aa][Pp][Ee]
do
echo -e $apefile
wavfile=${apefile//ape/wav}
echo -e ${wavfile}
done
输出如下
Underground 5.0.ape
Underground 5.0.wav
Underground 6.0.ape
Underground 6.0.wav
--------------------------------------------------------------------
我想的是for循环中一次处理一个文件所以可以完美的达到效果
运用最上面的3种写法,就算在某路径下只有一个ape文件也只有第一个调用ls的可
以达到效果 ..
我又做了其他很多实验,结果都是差不多的
-----------------------------------------------------------------
另外我也写了一个select的简单选项,查了man page好像有点不太一样
如下
71 echo -e "Do you want to del the wav file"
72 select wavdel in "Yes" "No"
73 do
74 break
75 done
76 if [ "wavdel" == "Yes" ]
77 then
78 echo -e "Wav file is removed"
79 rm $wavfile
80 elif [ "wavdel" == "No" ]
81 then
82 echo -e "Wav file is kept"
83 else
84 echo -e "Invaild input"
85 fi
--------------------------------------------------------------
另外其实昨天我放的附件错了 .... 重新放一个新的附件
附件是一个 怎么转都乱码的CUE文件
几个bash script的问题
-
- 帖子: 131
- 注册时间: 2008-04-03 12:46
- 来自: http://wdstudio.blogbus.com/
- 联系:
几个bash script的问题
- 附件
-
- CDImage.ape.cue.tar.gz
- 转都乱码的CUE文件
- (375 Bytes) 已下载 23 次
- eexpress
- 帖子: 58428
- 注册时间: 2005-08-14 21:55
- 来自: 长沙
-
- 帖子: 131
- 注册时间: 2008-04-03 12:46
- 来自: http://wdstudio.blogbus.com/
- 联系:
Re: 几个bash script的问题
不是很明白 ... 能解释下吗eexpress 写了:你这写法,似乎没一个可以通过带特殊字符的。
试试带空格的。