gpt4 book ai didi

linux - 读行时,只读最后一行

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:54:37 25 4
gpt4 key购买 nike

我有一个小的 bash 脚本,它应该读取一个文件并在 mplayer 中播放每一行。但它只播放每个文件的 1 秒,然后继续播放下一首歌曲。只有文件中的最后一行可以正常播放。这是我目前所拥有的:

#!/bin/bash

file=/home/dummy/list.m3u

echo "################################"
while IFS= read -r line
do
echo "loadfile '$line'" > /tmp/mplayer.fifo
done < $file

文件中的行仅包含 mp3 的路径,如下所示:/home/dummy/song.mp3

如何播放每一行并在歌曲结束后开始下一首歌曲?

另外,有没有办法以随机顺序读取行?

提前致谢。

最佳答案

Only the last line in the file is being played properly.

使用 >> 而不是 > 进行追加。您使用的 > 每次都会覆盖文件,因此您只能看到文件中的最后一行。

Also, is there a way to read the lines in a random order?

您可以使用shufsort:

while IFS= read -r line
do
echo "loadfile '$line'" >> /tmp/mplayer.fifo
done < <(shuf $file)

sort -R filename 将执行随机排序。

关于linux - 读行时,只读最后一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22190663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com