无法触摸bash脚本中具有var名称的文件进行循环

我正在为PiHole编辑脚本,以将adblock列表格式转换为dns格式,以供PiHole使用。 想法是滚动到一个lists.list文件,该文件包含指向不同列表的链接,对该文件的每个链接进行卷曲,并为每个名为$ link.list的链接创建一个包含所有dns名称的文件。

*问题是:* 我收到消息“触摸:无法触摸'https://easylist-downloads.adblockplus.org/easylistgermany.txt.list':没有此类文件或目录”

我试图查看是否存在某些权限问题,因此将其带到了home / user文件夹中。 如果我这样做

curl --silent $source >> ads.txt 

touch ads.txt

有效

这是我写的:

for sources in `cat lists.list`; do
    echo $source
    touch "$source".list
    echo `curl --silent $source` > $source.list
    echo -e "\t`wc -l $source.list | cut -d " " -f 1` lines downloaded"
done

然后我得到

https://easylist-downloads.adblockplus.org/easylist.txt
touch: cannot touch 'https://easylist-downloads.adblockplus.org/easylist.txt.list': No such file or directory

那么有什么建议吗? 谢谢您的宝贵时间!

chongqingwangjing 回答:无法触摸bash脚本中具有var名称的文件进行循环

这是因为您使用完整的URL作为文件名,但是文件名中不能包含斜线。您可以将文件命名为URL的最后一位吗?然后这应该工作:

#!/bin/bash

for source in `cat lists.list`; do
    echo $source
    filename=$(sed -E 's@.+/@@' <<< $source).list  # <-- remove everything up to and including the last slash
    curl --silent "$source" -o "$filename"
    echo -e "\t`wc -l $filename | cut -d " " -f 1` lines downloaded"
done
本文链接:https://www.f2er.com/3150973.html

大家都在问