如何在bash中循环传递变量

时间:2012-11-02 01:32:10

标签: bash

我在互联网上找到了一个脚本(https://calomel.org/youtube_wget.html),它可以播放youtube视频。

因此,通过简单输入./yt.pl youtubeLink,脚本可以完美地用于单个剪辑。 但是我想扩展它并从文本文档中的链接中使用它(download.txt) 。所以我在bash中创建了一个循环。循环看起来像这样。

`

    #!/bin/bash
wordCount=$(cat download.txt | wc -l)

for (( number=$wordCount; $number-lt$wordCount;number--))
do
        link=$(sed -n $number"p" download.txt)
        "./yt.pl "$link
        sleep 3
done

这个唯一的问题不起作用。它给我以下错误信息。

/auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=KYzUd95h8X4: No such file or directory

如果我只是运行错误消息./yt.pl http://www.youtube.com/watch?v=KYzUd95h8X4的这一部分,它可以正常工作。

这是ssh窗口的完整输出

./auto.sh: line 7: ./yt.pl : No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=XEAL23g2V6g: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=KYzUd95h8X4: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=IaADyDhg-CY: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=JmY4RCCCll4: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=D0p5RKzuJLU: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=sY6-PY9wWQ8: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=TRwcozVntTE: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=ft5hp90FV74&feature=relmfu: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=DB1E4M7bmeM: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=t6w4yeT6OTg&feature=relmfu: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=t-m88UZXn_8&feature=related: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=iix8NxDN6mQ&feature=relmfu: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=O3DvUKEZP_0&feature=relmfu: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=IKVdSNfbilo: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=V3kjn1zM7OI&feature=relmfu: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=EhJheZepqqY&feature=relmfu: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=59Oj_xpxh_g&feature=relmfu: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=DLP8XMMEG0A: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=pCY5ZRXQ3u0&feature=relmfu: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=a8CHv8n6qpI&feature=relmfu: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=afJXLpC95lQ&feature=relmfu: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=6q4dPeUjmu8&feature=relmfu: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=0BY5V56ZW3w&feature=relmfu: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=9CO__3nHsg8: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=bzgZlV3LzFA&feature=fvst: No such file or directory
./auto.sh: line 7: ./yt.pl http://www.youtube.com/watch?v=FgS1UQvYtcU&feature=fvst: No such file or directory

1 个答案:

答案 0 :(得分:2)

尝试这样做:

#!/bin/bash

while read link; do
    ./yt.pl "$link" && sleep 3
done < download.txt