0

I just realized, due to an error on my part, that though wget manual only mentions URL at the end, I am able to specify body-data option after the URL. This is quite convenient, but I am wondering if this is behavior as designed.

$ wget --method=PUT -O -  http://httpbin.org/put --body-data='abcdefg'
--2019-03-27 10:52:30--  http://httpbin.org/put
Resolving httpbin.org (httpbin.org)... 3.85.154.144, 52.71.234.219
Connecting to httpbin.org (httpbin.org)|3.85.154.144|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 415 [application/json]
Saving to: ‘STDOUT’

-                              0%[                                               ]       0  --.-KB/s               {
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "abcdefg": ""
  }, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "identity", 
    "Content-Length": "7", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "Wget/1.19.1 (cygwin)"
  }, 
  "json": null, 
  "origin": "50.203.83.51, 50.203.83.51", 
  "url": "https://httpbin.org/put"
}
-                            100%[==============================================>]     415 --.-KB/s    in 0s      

2019-03-27 10:52:30 (4.53 MB/s) - written to stdout [415/415]
2
  • Arguments are often accepted in any order (as you have found here)... though that isn't true across the board for all applications... it's a good idea to check that what's happening is what you expect.
    – Attie
    Mar 27, 2019 at 18:57
  • @Attie you are correct; named arguments are almost always unordered accept where order is significant. Unnamed arguments usually have to follow strict order as it may cause ambiguity. It is for this reason that I am looking for confirmation that this is as intended and not something that works perchance. For comparison curl has a named parameter --url/-u to allow specifying URL anywhere on command line Mar 27, 2019 at 19:13

1 Answer 1

1

Yes, this is supported behaviour. For the Wget command line, you can put the URLs anywhere.

EDIT: From info wget, Section 2.2, Option Syntax:

Since Wget uses GNU getopt to process command-line arguments, every option has a long form along with the short one. Long options are more convenient to remember, but take time to type. You may freely mix different option styles, or specify options after the command-line arguments. Thus you may write:

 wget -r --tries=10 http://fly.srk.fer.hr/ -o log
3
  • Thanks darnir. Is this documented somewhere? Mar 28, 2019 at 16:54
  • Yes it is, in info wget. I added the text to my answer.
    – darnir
    Mar 28, 2019 at 22:27
  • Thank you! It is in Section 2.2 of official wget manual at gnu.org that I linked to as well. Mar 28, 2019 at 23:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .