为什么我不能在变量赋值中使用通配符模式?
在 bash 中这是可行的:
var1=abc
但这会给出一个错误:
var*1=abc
var*1=abc: command not found
为什么会这样?为什么表达式被视为命令?
In bash this works:
var1=abc
But this gives an error:
var*1=abc
var*1=abc: command not found
Why so? Why is the expression treated as a command?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 http://www.gnu.org/software/bash/manual/bashref。 html
左侧的值不是标识符。这是一种表达。因此该命令(计算整个表达式)无效。
换句话说,名称中不能有星号,也不能通过进行一些数学运算(乘法)来生成变量名称。
From http://www.gnu.org/software/bash/manual/bashref.html
The value on the left hand side is not an identifier. It is an expression. Therefore that command (to evaluate the entire expression) is invalid.
In other words, you can't have asterisks in names, and you can't generate a variable name by doing some math (multiplying).
变量标识符的字符(星号)无效。
Invalid character (asterisk) for a variable identificator.
POSIX 定义 shell 变量名称由字母数字和下划线组成,并且不以数字开头。 (有一些特殊变量违反了这一点;它们始终是单个字符,并且不能与用户定义的变量发生冲突。)
POSIX defines shell variable names to consist of alphanumerics and underscore, and not starting with a digit. (There are special variables which violate this; they are always single characters, and they cannot collide with user defined variables.)