When and how do bash determine whether the input line is an assignment? -


if type in following 2 commands:

i=1 var$i=2014 

i error message var1=2014: command not found.

i have found how make dynamic variable names possible declare in this post, still wondering why error message generated. implies bash consider var1=2014 command/executable name instead of assignment, , if line assignment test happened before $i expansion.

qustion:

what order bash follow parsing input line w.r.t. assignments?

any recommended reading appreciated.

first checks whether command looks assignment or ordinary command invocation.

then performs variable substitutions, command substitution, etc. has after determining type of command line, because variable substitution different when goes assignment. instance, there's no word splitting when write:

var=$variable 

but there word splitting when write:

command $variable 

finally, after substitutions, word splitting, globbing, executes command. if determined assignment, assigns variable; otherwise, executes command.

in case, since

var$i=2014 

is not valid assignment syntax, first step determines it's command, last step tries execute such.

this simplified.

you should try avoid using variable variables -- can achieve same result more using array.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -