13

It is said that in UNIX and other alike systems, we can use hyphen for username in addition to Latin characters, numerics and underscore. On the other hand, the hyphen character is used as operator in so many programming languages. Are they compatible with each other?

I'm wondering whether hyphens in username could be sometimes regarded as minus operator and cause unintended behavior in certain program codes. If this could happen, I would use underscore for delimiter in username.

Thank you for your help in advance.

Merzong
  • 233
  • 1
    It's definitely available. I personally haven't seen anything used but alphabetical and occasionally numeric, but if the character is allowed then a well-written program will be prepared to deal with it correctly. "Unintended behavior with certain program codes" essentially is asking "do some programs have bugs?" which is an unqualified "yes". But since it's "do some programs have this specific bug" then I have no idea. – Wildcard Nov 14 '15 at 05:19

1 Answers1

15

On the other hand, the hyphen character is used as operator in so many programming languages.

True. However, few (no?) language interprets literal strings and execute operations in them blindly. If that were the case, we should be more afraid of usernames being treated as method names! The problem is with developers who assume a restricted set of valid characters.

If it helps, Debian's /etc/adduser.conf lists permitted characters in usernames: alphabets, numbers, hyphens and underscores.

$ tail /etc/adduser.conf
[snip]

# check user and group names also against this regular expression.
#NAME_REGEX="^[a-z][-a-z0-9_]*\$"

So, at least one major distribution supports you. Go ahead.

muru
  • 72,889
  • Glad to hear that I can safely use hyphen! Actually, I use OS X and I cannot find /etc/adduser.conf in it. Does Darwin also have its counterpart of NAME_REGEX? I'd like to check it if it exists. – Merzong Nov 14 '15 at 12:13
  • 1
    @Merzong AFAIK OSX allows Unicode characters in usernames. Hyphens are small change, comparatively. I don't have a Mac around to check, but you might find http://superuser.com/a/435606/334516 useful. – muru Nov 14 '15 at 12:20