Is there a way to programmatically detect if the currently installed wget supports a given feature; for example, IRI support?

I’m asking because I’d like to add these lines to my .wgetrc:

# Use UTF-8 as the default system encoding
local_encoding = UTF-8

But this makes wget unusable if it doesn’t support the local_encoding setting.

So, I’d like to conditionally configure this setting, only if wget supports the feature.

In Vim (.vimrc files) you can do this using has() and exists():

if has("autocmd")
  " Define autocommands here

How can I do something similar for wget in .wgetrc?


You cannot include any extra logic into .wgetrc, so using shell initialization as described in enzotib's answer seems to be the only possibility.

Beside of --help, you can get the build configuration of GNU’s wget and therefore the enabled features via --version:

if wget --version | grep -q "+iri"; then 
    # modify ~/.wgetrc

In the case you need to test if a feature is also included in busybox’s wget, you need to know that is does not support --version and prints instead its "--help" to stderr (not stdout as GNU’s wget).


What about this in some shell initialization script?

if wget --help | grep -q "local-encoding"; then 
    # modify ~/.wgetrc
  • I like it! I’d prefer a solution that keeps all the logic in the .wgetrc file itself, but I guess that’s just not possible, then. – Mathias Bynens Mar 22 '12 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.