$ ls *mp3 | xargs mplayer
Playing Lemon.
File not found: 'Lemon'
Playing Tree.mp3.
File not found: 'Tree.mp3'
Exiting... (End of file)
命令失败是因为文件“Lemon Tree.mp3”,MP3包含空格,所以xargs认为它是两个文件。该如何处理?
xargs实用程序从标准输入中读取空格、制表符、换行符和文件结束分隔字符串,并以字符串作为参数执行实用程序。
避免使用空格作为分隔符,可以通过更改xargs的分隔符来完成。
find . -name "*.mp3" -print0 | xargs -0 mplayer
至于每七次播放一次mp3的问题,如下命令:
mplayer "$(ls | grep mp3 | sed -n 7p)"