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.
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.
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.
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.
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.
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.
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 -.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With