[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#34026: mention that long options aren't always as good as short opti

From: Eric Blake
Subject: bug#34026: mention that long options aren't always as good as short options
Date: Wed, 9 Jan 2019 22:10:55 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1

On 1/9/19 7:47 PM, 積丹尼 Dan Jacobson wrote:
> On (info "(coreutils) Common options")
> mention that, though clearer, long options aren't always as good as short 
> options,
> $ touch --reference=~jidanni/.pcmanx /cf/pcmanx_time
> touch: failed to get attributes of '~jidanni/.pcmanx/pcmanx': No such file or 
> directory
> Unless one removes the '=':
> $ touch --reference ~jidanni/.pcmanx/pcmanx /cf/pcmanx_time
> $
> (due to the shell helping out with "~...")

The same is true for short options: 'touch -rfile' and 'touch -r file'
are almost identical, except for 'touch -r~file' and 'touch -r ~file'.
So it is NOT a case of long options not being as good as short options.

Note that bash defaults to doing ~ expansion after =, but that this is a
bash extension and is disabled by default when bash is in POSIX mode.
But not even bash can tell that you want tilde expansion if you write
the argument of a short option adjacent to the option rather than as a
separate argument.  So in _that_ regards, if you want to pass as small
of an argv[] as possible, the long option form with = is BETTER than the
short option form of concatenation, if you use bash as your shell.

Spelling long options with a space instead of = is fine for all long
options that have a mandatory option, and we try to avoid long options
with optional arguments (where you have to use =).  That said, I agree
that having some mention in the manual of the effects of =~ having
different behaviors depending on the shell would be helpful.  Remember,
if you want tilde expansion it is best to present that option argument
as a standalone argument so that the tilde starts the word; when that is
not possible (such as for the less common case of an optional argument
to a long option), you can use $HOME/ instead of ~/, or else have to
resort to a temporary variable to perform the tilde expansion
separately, as in:

tmp=~user; touch --reference=$tmp/.pcmanx/pcmanx /cf/pcmanx_time

Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]