Many command line utilities accept long ("GNU style", according to ) options such as
--version. To my surprise, truncated versions are often interpreted as the full option. For example,
df from GNU Coreutils gives
user@computer ~ $ df --version df (GNU coreutils) 8.32 Packaged by Gentoo (8.32-r1 (p0)) Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Torbjorn Granlund, David MacKenzie, and Paul Eggert.
The same output is obtained by replacing
--version with any of the truncated variants
--versio. However, when I add additional letters to the option, it suddenly realises that the option is invalid:
user@computer ~ $ df --versionn df: unrecognized option '--versionn' Try 'df --help' for more information.
Is this behaviour intentional? What is the reasoning is behind it?
My understanding is that most utilities rely on
getopt (or similar), so I have looked into their manpages for clues, but not found any explanation.
 E. S. Raymond. The Art of UNIX Programming. Pearson Education, Inc, 2004