- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想检查远程网站上的一些文件。
这里是bash命令生成计算文件md5的命令
[root]# head -n 3 zrcpathAll | awk '{print $3}' | xargs -I {} echo wget -q -O - -i {}e \| md5sum\;
wget -q -O - -i https://example.com/zrc/3d2f0e76e04444f4ec456ef9f11289ec.zrce | md5sum;
wget -q -O - -i https://example.com/zrc/e1bd7171263adb95fb6f732864ceb556.zrce | md5sum;
wget -q -O - -i https://example.com/zrc/5300b80d194f677226c4dc6e17ba3b85.zrce | md5sum;
然后我将输出的命令通过管道传输到 bash,但只执行了第一个命令。
[root]# head -n 3 zrcpathAll | awk '{print $3}' | xargs -I {} echo wget -q -O - -i {}e \| md5sum\; | bash -v
wget -q -O - -i https://example.com/zrc/3d2f0e76e04444f4ec456ef9f11289ec.zrce | md5sum;
3d2f0e76e04444f4ec456ef9f11289ec -
[root]#
最佳答案
请您尝试以下方法:
while read -r _ _ url _; do
wget -q -O - "$url"e | md5sum
done < <(head -n 3 zrcpathAll)
我们不应该把 -i
放在 "$url"的前面。
[关于-i选项的解释]
wget
的联机帮助页说:
-i file
--input-file=file
Read URLs from a local or external file. [snip]
If this function is used, no URLs need be present on the command line. [snip]
If the file is an external one, the document will be automatically treated as html if the Content-Type matches text/html.Furthermore, the file's location will be implicitly used as basehref if none was specified.
文件
将包含 url 行,例如:
https://example.com/zrc/3d2f0e76e04444f4ec456ef9f11289ec.zrce
https://example.com/zrc/e1bd7171263adb95fb6f732864ceb556.zrce
https://example.com/zrc/5300b80d194f677226c4dc6e17ba3b85.zrce
而如果我们使用 -i url
选项,则首先使用 wget
将 url
下载为包含 url 行的文件如上。在我们的例子中,url
是下载自身的目标,不是 url 列表,wget
会导致错误:No URLs found in url
。
即使 wget
失败,为什么命令只输出一行,而不是md5sum
的结果是三行?这似乎是因为 head
命令立即刷新了剩余的管道子进程失败时的行。
关于bash - 如何将多个命令通过管道传递给 bash?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71403947/
我是一名优秀的程序员,十分优秀!