Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个循环的脚本:
#!/bin/sh while [ true ] do mpc current > current_song.txt mpc idle player done
但是有时它无法获取歌曲详细信息并创建一个空白文件。FFMpeg 正在读取这个文件,如果它为空,它会崩溃。有什么方法可以保证脚本的安全,所以如果文件是空白的,它会添加特定的文本?
最好的方法是创建一个尝试读取文件的脚本,如果它变成空白插入一些文本然后休眠一段时间,还是有更优雅的方法来做到这一点?
如果文件确实为空(“ls -l”显示长度为 0),您可以使用以下内容将一些文本放入文件中:
#!/bin/sh while true do mpc current > current_song.txt if [ ! -s current_song.txt ]; then echo SongNotFound.mp3 > current_song.txt fi mpc idle player done