0

I wright a documentation so I prefer use long options because it’s self-descripting. --output-document= is more readable than his short equivalent -O.

Then, I have to indicate a file in the home directory, but the ~ character failed when I try --output-document=~/.vimrc.

I really need to use a long option but I also need to indicate a path witch automatically contain the home directory.

So, there is a solution witch not use a syntax like /home/<your name>/?

0

3 Answers 3

4

Tilde expansion only works in the beginning of a word. (At least in bash, see e.g. https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html )

You could use, say --something=$HOME/filename if you only need to refer to the current user's home directory. Since --output-document takes a mandatory argument, writing the argument in a separate option works too, but for optional arguments it doesn't seem to work (*), so you probably want to use the --foo=bar format usually.

If the context is documentation, it might be useful to at least mention the corresponding short options too since they are shorter to write and your readers might stumble upon them in code written by others anyway. Especially for common options like wget -O.

(* For example, try ls --color=auto vs ls --color auto. I said "seem to", since the most direct mention of this I can find is the man page of the command line program getopt, the library documentation isn't as clear.)

1

As far as I know the '=' shouldn't be there...

wget --option-document ~/.vimrc 
0

I wouldn't use in documentation, nor 'in anger', but if you really want tilde you can do either of

VAR=~/.vimrc; wget ... --output-document="$VAR" unset VAR # to keep things tidy # or put in ( subshell ) to keep pre-existing VAR # quotes only needed if $HOME (or anything you substitute for .vimrc) # can contain whitespace or glob characters ?*[ which is pretty rare wget ... --output-document="$(echo ~/.vimrc)" # or if $HOME can begin with - or contain backslash, also pretty rare: wget ... --output-document="$(printf '%s\n' ~/.vimrc)" # both times quotes as above 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.