为什么我的脚本只有在我^ D之后才结束?

问题描述 投票:0回答:1

我有一个脚本,可以接收youtube链接,并使用youtube-dl将视频的可用分辨率提取到“ res.txt”文件中。 res.txt文件包含所需的输出,但仅在按^ D后显示。有人可以告诉我为什么我的脚本卡住了吗?

#!/bin/bash
youtube-dl -F https://www.youtube.com/watch?v=jVv_aSTVpyI > info.txt
echo Start
cat > res.txt
for i in '144p' '240p' '360p' '480p' '720p' '1080p' '1440p' '2160p' ; do
    while read p ; do
        if [[ "$p" == *"$i"* ]] ; then
            echo "$i" >> res.txt
            break
        fi
    done < info.txt
done 
echo "done"
bash shell stdin
1个回答
0
投票

这将更短,更有效:

youtube-dl -F https://www.youtube.com/watch?v=jVv_aSTVpyI |
  grep -oE '(144|240|360|480|720|1080|144|2160)p' |
    sort -u > res.txt
  • [grep -oE:提取与扩展的Regex匹配的行,仅打印匹配的部分。
  • sort -u:对行进行排序并删除重复项。
© www.soinside.com 2019 - 2024. All rights reserved.