Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
endif

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

share|improve this question
add comment

2 Answers

What about this in some shell initialization script?

if wget --help | grep -q "local-encoding"; then 
    # modify ~/.wgetrc
fi
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
add comment

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
fi

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
add comment

Your Answer

 
discard

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.