1

According to systemd's enforced User/Group Name Syntax, the set of one is defined by the exact same rules as for POSIX, i.e. «lower and upper case ASCII letters, digits, period, underscore, and hyphen» in a random sequences, as well for Debian‑based OS's.

... the value shall be composed of characters from the portable character set (except NUL and as indicated below).

Therefore, the definition of user name valid string forward compatible with POSIX environmental variables and quotes around $USER variable can be omitted in commands like chown or install?

2
  • 2
    USER=kamil; IFS=m; printf '%s\n' $USER Commented Jul 12, 2021 at 11:25
  • note that the page you link to says "The values that the environment variables may be assigned are not restricted except that they are considered to end with a null byte [plus total length limit]", so pretty much anything is compatible with it. Commented Jul 12, 2021 at 11:29

1 Answer 1

3

The systemd page you link to, says:

Relaxed user/group name syntax is enforced whenever a systemd component accepts and makes use of user/group names registered by other (non-systemd) components of the system [...]

and the rules there seem to allow e.g. whitespace in the middle of the user name. Earlier in the page, it mentions that at least sssd generates names like that.

So, even if it technically works to not quote a variable expansion when you're s u r e the value doesn't contain IFS characters or glob characters, it's probably a good idea to consider how sure you are, and if it would be just easier to use the quotes instead of verifying all possible sources of the values and all possible parts of code that might change IFS.

You must log in to answer this question.