发表于 : 2008-08-31 19:46
..谁以前好像写过一个
应该在脚本里读取文件名的时候加个引号就成了吧adagio 写了:我知道了,LZ这个脚本有个缺陷,就是如果目录名有空格就放不了,这个不太好啊,你再改改?
想入非非 写了:这个还是鼓励原创的精神但是没什么必要
直接安装一个xmms2,一切就解决了
代码: 全选
#!/bin/bash
#kill players
killall mplayer mpg123;
if [ "`ps aux |grep mplayer |grep -v grep|wc -l`" != 0 ];then
kill -9 `ps aux |grep mplayer |grep -v grep|awk {'print $2'}`
fi
#clean
if [ -s /tmp/mlist ]; then
rm /tmp/mlist
fi
#make play list
dr=`pwd`
#dr=`dirname "$1"`
#cd "$dr"
#st=${1##*\/}
st="`echo "$1"|sed 's/\[/\\\[/g;s/\]/\\\]/g'`"
echo "$st"
list="`ls "$dr"|grep -v ".jpg"|grep -v ".srt"`"
a="`echo "$list"|grep -n "$st"|sed -n 1p|awk -F : '{print $1}'`"
b="`echo "$list"|wc -l`"
#error manage
c=$#
if [ -z $a ];then a=1;c=0;fi
#######
for((i=$a;i<=$b;i++))do
if [ $c = 0 ];then
song="`echo "$list"|sed -n $i,$(($i))p`"
echo "$dr/$song" >>/tmp/mlist
else
song="`echo "$list"|sed -n $i,$(($i))p`"
song1="`echo "$song"|sed 's/\[/\\\[/g;s/\]/\\\]/g'`"
need_list="`echo "$*"|grep "$song1"|wc -l`"
if [ $need_list = 1 ];then
echo "$dr/$song" >>/tmp/mlist
fi
fi
done
#play with list
if [ -s /tmp/mlist ]; then
if [ $c = 0 ];then
mplayer -playlist /tmp/mlist
else
mplayer -playlist /tmp/mlist -loop 0
fi
#clean
rm /tmp/mlist
fi
exit