32

While setting up a sudo environment I noticed that the include directive is prefixed with the pound (#) character.

Solaris shows this as:

## Read drop-in files from /etc/sudoers.d
## (the '#' here does not indicate a comment)
#includedir /etc/sudoers.d

The manual (Linux as well as Solaris) states:

Including other files from within sudoers It is possible to include other sudoers files from within the sudoers file currently being parsed using the #include and #includedir directives.

And:

Other special characters and reserved words The pound sign (`#') is used to indicate a comment (unless it is part of a #include directive or unless it occurs in the context of a user name and is followed by one or more digits, in which case it is treated as a uid). Both the comment character and any text after it, up to the end of the line, are ignored.

Does anybody knows why the choice was made to use the pound character in the #include and #includedir directives?

As a side note: I often use something like egrep -v '^#|^$' configfile to get the non-default/active configured settings, and this obviously does not work for the sudoers file.

31

#include was added in 2004. It had to be compatible with what was already there. I don't think include /path/to/file would have been ambiguous, though, but it might have been a little harder to parse, because the parser would have to distinguish include /path/to/file (include directive) from include = foo (allow the user include to run the command foo).

But I think mostly the reason was to look like the C preprocessor, which the manual explicitly cites as inspiration.

  • Nice catch and explanation, unfortunately those explanations are removed from the manuals (at least on Ubuntu, RedHat, OpenBSD and Solaris). – Lambert Nov 20 '15 at 7:11
  • 2
    Oh man, I just wasted a solid hour on this. Thank you! – Andrew Jul 29 '17 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.