Search code examples
bashdeclare

variable declaration is considered as a command in bash


Why is int"$((++k))"=test considered as a command by bash? Example:

$ int1=test
$ int"$((++k))"=test
bash: int1=test: command not found
$ 

I know that I could use declare int"$((++k))"=test, but why doesn't int"$((++k))"=test work?


Solution

  • This behavior is specified in POSIX 2.10.2.7 on the Shell Command Language (emphasis mine):

    If all the characters preceding '=' form a valid name (see the Base Definitions volume of IEEE Std 1003.1-2001, Section 3.230, Name), the token ASSIGNMENT_WORD shall be returned. (Quoted characters cannot participate in forming a valid name.)