Saturday, November 14, 2009

Bash bad substitution error - array access

If you ever come across this error while migrating a
shell script from one machine to other, please ensure
that you are using the same shell to execute the script.

Typical error-
test.sh: 4: A[9]=123213: not found
test.sh: 5: Bad substitution

i.e if you used "sh filename.sh" to execute the file, please try
running it using "bash filename.sh". It solved the problem
for me. It had nothing to do with malformed braces while
accessing the array nor user permissions on the script.

Good luck!

4 comments:

Anonymous said...

Hey thanks it worked for me!

Anonymous said...

Same here but why?

misfit said...

The reason it works is because when you say bash you are explicitly asking the for the bash shell interpreter, instead of using a generic shell request command. I am not sure if this is the exact reason, but I would be happy if someone could correct me.

Anonymous said...

Thanks a lot!

Post a Comment