Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It is not. -i'' is exactly the same thing as "-i", and while GNU sed interprets this as an empty suffix, BSD sed expects -i to take an argument normally, and will treat the next argument as the extension. If you instead use sed -i "", as is appropriate with a BSD sed, GNU sed will interpret that as the empty program and try to read from a file named your actual script.


I hate that behavior of GNU sed (and also of mktemp). Having a flag optionally take an argument is just so weird and surprising, and the syntax is always unexpected and inconsistent.


I don't see it as a flag that optionally takes an argument, but rather a flag that makes an optional argument mandatory.


No, that's how optional flags should work. I mean how specifically -i works. With GNU sed:

-lN, --line-length=N, -l N, --line-length N

All work the same, set line length to N.

-iSUFFIX --in-place=SUFFIX, -i NEXTARG --in-place NEXTARG

Don't all work the same. The argument is only actually taken if it's attached to the flag directly. In the latter two forms, no backup is made.

GNU mktemp is similarly annoying, but different, with the --tmpdir flag.

-pDIR, --tmpdir=DIR, -p DIR, --tmpdir NEXTARG

Only the last one is different. If you use --tmpdir literally without attaching an argument to it, it defaults to $TMPDIR, otherwise it takes in DIR.

This is inconsistent and unpredictable. A flag should either take an argument or not.

I also dislike Python's argparse variable-length nargs behavior for similar reasons. Even with an integer nargs, it makes for an ugly command line, but with variable-length ones it just gets hideous, and can make it impossible to pass an argument beginning with a hyphen to a flag.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: