下面的程式實現一個簡單的mp3播放功能,可以設定路徑對所有mp3檔案進行搜尋並順序播放。
#!/bin/sh# very simple example shell script for mp3 player# 2014-5-6 by slwang#實現搜尋所有mp3檔案並順序播放歌曲path1=~/Musicpath2=~/Downloadstemp_file=/tmp/temp_files$$musicset=""menu_choice=""isnext="n"trap 'rm -f $temp_file && audacious -s' EXITset_menu_choice() {clearecho "mp3 player menu :-"echo " p) play"echo " u) pause"echo " s) stop"echo " n) next"echo " c) count"echo " l) list"echo " q) quit"echo "please input: \c"read menu_choice}clearecho "welcome to mp3 player"sleep 1IFS=""find $path1 $path2 -name *.mp3 -print > $temp_filemusicset=$(cat $temp_file)#more $musicset > $temp_filefor music in $musicsetdoecho "Beign to play $music"audacious -h $musicisnext="n"while [ "$isnext" = "n" ]doset_menu_choicecase $menu_choice inp) audacious -p;;u) audacious -u;;s) audacious -s;;n) isnext="y";;c) IFS=" "set $(wc -l $temp_file)lines=$1echo "total include $lines songs"echo "press return"IFS=""read x;;l) more $temp_fileecho "press return"read x;;q) exit 0;;esacdonedoneIFS=" "rm -f $temp_fileaudacious -secho "finished"exit 0
(轉載請註明作者和出處:http://blog.csdn.net/awakewind 未經允許請勿用於商業用途)