When expanding the /etc/passwd GECOS field to get the user's full name, should we expand only the first ampersand (& character), or all ampersands?

In a GECOS field with comma (,) delimited subfields, should ampersands only be expanded in the first subfield (i.e. the user's full name) or in all subfields?

If the Unix username contains capital letters, should we preserve them in the & expansion, or should we only capitalize the first letter of the username and lowercase the rest?

  • Going by OpenBSD's manpage: "The full name may contain an ampersand (‘&’)" ... which system are you asking about?
    – muru
    Aug 12, 2019 at 14:50
  • Thanks. Asking about a portable solution in the hopes that there is one. If not, we can use this question to gather a list of the behavior of different systems. That's the next best thing. Which software could be used as a reference to resolve questions like this? I don't suppose the finger daemon is in vogue anymore.
    – Lassi
    Aug 12, 2019 at 14:54

1 Answer 1

  • Ampersands should only be expanded in the first comma-delimited subfield (i.e. the so-called "full name" or "real name" subfield). If there are no commas in the GECOS field, treat the entire field as the real name.
  • Any and all ampersands are expanded, not only the first one.
  • If the first character of the username is an ASCII lowercase letter, that letter is uppercased in the ampersand expansion. Otherwise it is left intact. No case conversion is done to characters other than the first one.

The de facto authoritative sources for this information are sendmail server and finger client implementations. Implementations for BSDs and Solaris are open source, and all of them would seem to agree on the above rules.

The GECOS field is no longer an up-to-date name for this field. It would more accurately be called the finger field since on almost all systems the expected layout of the comma-separated subfields comes from finger.

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.