Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wget: what does this trailing dash represent/do?

Tags:

shell

wget

wget http://ipinfo.io/ip -qO -

I'm new to bash and can't seem to figure out what that trailing dash character does (or why it is required in this command).

Any help is much appreciated.

like image 953
RobertJoseph Avatar asked Nov 30 '15 19:11

RobertJoseph


People also ask

What does the dash mean in Linux?

dash is the standard command interpreter for the system. The current version of dash is in the process of being changed to conform with the POSIX 1003.2 and 1003.2a specifications for the shell.

What does wget flag do?

The [option] flag lets you specify the action to perform with the wget command. The [URL] flag points to the address of the directory, file, or webpage that you wish to download.

What is dash in tar?

So, in answer to your question, the dashes mean stdout when creating/writing a tarfile with tar cf and stdin when extracting/reading a tarfile with tar xf. Follow this answer to receive notifications.

What is wget spider?

The wget tool is essentially a spider that scrapes / leeches web pages but some web hosts may block these spiders with the robots. txt files. Also, wget will not follow links on web pages that use the rel=nofollow attribute. You can however force wget to ignore the robots.


2 Answers

By convention (which not all programs follow), a dash in filename position refers to stdin or stdout, as appropriate. Since this is an argument to -O (output), it refers to stdout.

A more verbose way to write this (on Linux or other operating systems where /dev/stdout is usable by programs other than just the shell) would be:

wget http://ipinfo.io/ip --quiet --output-document=/dev/stdout

As it happens, this behavior is defined by the POSIX Utility Syntax Guidelines. Specifically:

Guideline 5: One or more options without option-arguments, followed by at most one option that takes an option-argument, should be accepted when grouped behind one '-' delimiter.

...thus, -qO is treated identically to -q -O.

Guideline 13: For utilities that use operands to represent files to be opened for either reading or writing, the '-' operand should be used to mean only standard input (or standard output when it is clear from context that an output file is being specified) or a file named -.

...thus, the behavior regarding - is explicitly specified.

like image 120
Charles Duffy Avatar answered Sep 30 '22 16:09

Charles Duffy


To print the output at the STDOUT which is usually your terminal.

See the manpage for wget which says :

-O file --output-document=file The documents will not be written to the appropriate files, but all will be concatenated together and written to file. If - is used as file, documents will be printed to standard output, disabling link conversion. (Use ./- to print to a file literally named -.)

like image 45
sjsam Avatar answered Sep 30 '22 15:09

sjsam