shell - wget 屏幕输出无法使用 shell 脚本重定向到日志文件

标签 shell

我有一个shell脚本,内容如下
我希望屏幕输出可以重定向到临时日志,
屏幕输出不是 html 内容,而是像

--2012-10-30 15:53:14--  http://www.youtube.com/results?search_query=pig
Resolving www.youtube.com... 173.194.34.5, 173.194.34.6, 173.194.34.7, ...
Connecting to www.youtube.com|173.194.34.5|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “search_result”

    [ <=>                                   ] 108,503     --.-K/s   in 0.07s   

2012-10-30 15:53:15 (1.40 MB/s) - “search_result” saved [108503]

但它不能
我试过 2>&1|cat > templog
还是不行

您可以复制内容并制作一个 wget.sh 文件,然后运行它
您会注意到内容无法重定向到 templog,

如何处理这个以实现我的目标?
谢谢
keyword=pig
page_nr=3
wget -O search_result http://www.youtube.com/results?search_query=${keyword}&page=${page_nr} > templog

最佳答案

你只需要在你的网址周围加上引号。 wget然后使用 stderr 在屏幕上打印,因此您还必须使用 stderr 而不是 stdout (使用 2> 而不是 > ):

keyword=pig
page_nr=3
wget -O search_result "http://www.youtube.com/results?search_query=${keyword}&page=${page_nr}" 2> templog

关于shell - wget 屏幕输出无法使用 shell 脚本重定向到日志文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13141721/

相关文章:

java - 在 java 中,出现错误 "Cannot run program "/bin/sh“: java. io.IOException : error=24, 打开的文件太多”

regex - 匹配引号中的文本(新手)

shell - 什么是 shell 形式和 exec 形式?

shell - 在 shell 脚本中更改为 root 用户

linux - 运行 shell 脚本时出现 PAM 对话错误

linux - 仅当 Linux bash 中存在子文件夹时,才获取带有文件名的当前目录(非完整路径)

linux - 有 Linux 操作系统中的 Bash 脚本编写示例吗?

regex - Find 命令中的正则表达式

bash - 读取stdout时如何保留shell脚本行距?

perl - 如何将 local::lib 与 fish shell 一起使用?