在bash这个工程:为什么我不能在变量赋值中使用通配符模式?
var1=abc
但是,这给出了一个错误:
var*1=abc
var*1=abc: command not found
为什么会这样?为什么表达式被视为命令?
在bash这个工程:为什么我不能在变量赋值中使用通配符模式?
var1=abc
但是,这给出了一个错误:
var*1=abc
var*1=abc: command not found
为什么会这样?为什么表达式被视为命令?
从http://www.gnu.org/software/bash/manual/bashref.html
name
A word consisting solely of letters, numbers, and underscores, and beginning with a letter or underscore. Names are used as shell variable and function names. Also referred to as an identifier.
在左手侧的值不是一个标识符。这是一个表达。因此该命令(评估整个表达式)无效。
换句话说,您不能在名称中包含星号,并且您无法通过执行一些数学运算(乘法)来生成变量名称。
变量标识符的无效字符(星号)。
POSIX定义外壳变量名称由字母数字和下划线组成,而不是以数字开头。 (有些特殊变量违反了这个规则;它们总是单个字符,它们不能与用户定义的变量相冲突。)
3.230 Name
In the shell command language, a word consisting solely of underscores, digits, and alphabetics from the portable character set. The first character of a name is not a digit.
很酷,感谢您的参考! – abc