On 8/14/19 7:01 AM, Harald Dunkel wrote: > Hi folks, > > I just learned by accident that > > var="-n" > /bin/echo -- $var > > actually prints > > -- -n
Correct. This is the POSIX-mandated behavior. > > Shouldn't it be just > > -n No, because 'echo' is one of the few exceptions to the rule, in that POSIX specifically mandates that it NOT recognize -- as an end-of-options marker. Instead, POSIX recommends that you use printf instead of echo if the string you are intending to print may contain \ or start with -. > ? > > Other tools in coreutils use '--' to indicate "stop parsing for > command line flags", e.g. touch, ls and rm: > > % /bin/touch -- -l > % /bin/ls -- -l > -l > % /bin/rm -- -l > % /bin/rm -- -l > /bin/rm: cannot remove '-l': No such file or directory > > Some common style would be nice here. It would be nice, but it would be non-compliant to the standards. We can't change this one. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature