Quietly clobbering with GNU sed
SoftwareHere's something fun my boss and I discovered today. Say you have this file:
$ cat test.txt ==> Zettai ryouiki in all the examples
And you want to replace a word with sed. You see GNU sed has a quiet flag, so thinking it means surpress warning messages and such (useful in scripts), you run this:
$ sed --quiet -i '' 's/all/some/g'
Checking the file again, you’re astonished to find:
$ cat test.txt ==> *crickets*
There’s nothing there. Kaput. It has ceased to exist, like a legendary feathered creature. Exactly what you’d expect for a function called quiet?
Not to get all Malcom Gladwell on you, but turns out the GNU folks decided quiet would be used in this context:
-n
--quiet
--silent
By default, sed prints out the pattern space at the end of each cycle through the script (see How sed works). These options disable this automatic printing, and sed only produces output when explicitly told to via the p command.
A perfectly reasonable, useful function. But I feel anything with the capability to clobber a file should be given a command with a less innocuous name.
sed on my beloved BSDs doesn’t have a quiet flag, and therefore there’s no such convenience/confusion.