开发者

Why can't I use wildcard patterns in variable assignments?

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?


From 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.

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 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.)

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜