Unix如何解释$?

Unix如何解释$?
[orca@orcacomputers public_html]$ adduser Jé$$è+rèè
adduser: invalid user name 'Jé28956è+rèè'

我在CentOS7中添加用户时无法使用$。凯伦问道:“你到底为什么要这么做!?”当她在社会上把我钉在十字架上时,因为我是一个左撇子尼安德特人,做真实的自己。好奇心。

我的职业是审计员,因此当我整理数据时,我的幸福感会增加。那么$在这里告诉unix什么呢?到目前为止我能做的就是$$=28956在unix下。这是一个随机字符串吗?

有什么方法可以使用$字符对数据进行排序吗?或任何其他被认为对计算机科学目的有效的用例?

[orca@orcacomputers public_html]$ adduser Jéssè+rèè
adduser: invalid user name 'Jéssè+rèè'

真的是什么!?这是我必须自己分发的地方吗?

答案1

除了 BlueManCZ 关于如何转义特殊字符的答案之外,您提出的用户名还包含许多无效字符。请参阅 CentOS 7 的 adduser 手册页,在 CAVEATS 部分下:

CAVEATS
       You may not add a user to a NIS or LDAP group. This must be performed on the corresponding
       server.

       Similarly, if the username already exists in an external user database such as NIS or LDAP,
       useradd will deny the user account creation request.

       Usernames may contain only lower and upper case letters, digits, underscores, or dashes. They
       can end with a dollar sign. Dashes are not allowed at the beginning of the username. Fully
       numeric usernames and usernames . or .. are also disallowed. It is not recommended to use
       usernames beginning with . character as their home directories will be hidden in the ls
       output. In regular expression terms: [a-zA-Z0-9_.][a-zA-Z0-9_.-]*[$]?

您可以找到手册页的在线副本这里。因此,虽然$是用户名中的有效字符,但它仅在末尾有效。另外,+带有重音符号的字母egè在CentOS的adduser实现中永远不会有效。

是的,如果您不喜欢它,您可以自由地推出自己的。你可以找到源代码这里

答案2

shell 将其解释$为特殊字符。$$在你的情况下返回当前 shell 的 PID。如果要$在字符串中使用,则必须使用反斜杠对其进行转义\$

例如:

echo Jé\$\$è+rèè

Jé$$è+rèè

相关内容