Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to programatically 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?

share|improve this question

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).

share|improve this answer

What about this in some shell initialization script?

if wget --help | grep -q "local-encoding"; then 
    # modify ~/.wgetrc
share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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