What does “wget -O” mean?

瘦欲@ 提交于 2019-12-20 08:57:11

问题


I have an wget command like this in my shell script:

reponse="`wget -O- http:localhost:8080/app/index.html`"

I don't understand the -O- option. I was explained that -O is output to somewhere and - is output to the current stream. I don't see any explaination of "-" in wget. Is that a standard thing for shell scripting. Where I can find reference to it?

Thanks,


回答1:


Here's the man page of wget -O:

http://www.gnu.org/software/wget/manual/html_node/Download-Options.html#Download-Options

Here's a few examples:

  1. wget with no flag

    wget www.stackoverflow.com
    

    Output:

    A file named as index.html

  2. wget with -O flag

    wget -O filename.html www.stackoverflow.com
    

    Output:

    A file named as filename.html

  3. wget with -O- flag

    wget -O- www.stackoverflow.com
    

    Output:

    Output to stdout




回答2:


for the manual of wget: use man wget if you are on Unix platform. Else, try "man page wget" on google.

The -O- stand for "Get as a file and print the result on STDOUT"




回答3:


Depending on your system you should be able to find reference by typing man wget. The GNU Wget man page says this of the -O|--output-document flag:

If - is used as file, documents will be printed to standard output, disabling link conversion. (Use ./- to print to a file literally named -.)

And continues…

Use of -O is not intended to mean simply "use the name file instead of the one in the URL;" rather, it is analogous to shell redirection: wget -O file http://foo is intended to work like wget -O - http://foo > file; file will be truncated immediately, and all downloaded content will be written there.

It's not uncommon to see combined with -q and written as -q0- or -q0 - followed by a uri. It validates against the POSIX standard so, yeah, I'd say it's a standard thing for shell scripting.



来源:https://stackoverflow.com/questions/9830242/what-does-wget-o-mean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!