variable interpolation in shell script

A very common mistake:


As jlliagre pointed out you need to use braces around the part of the string you want bash to treat as a variable name. Otherwise it will only stop treating the string as the name when it gets to a character that can't be part of the name.

In this case FILE_error is being treated as the name of the variable because _ is allowed in variable names. You actually only want the FILE part, so you have to tell bash that specifically by putting braces around that part as ${FILE}_error.

In your example FILE_error was never set, so it expands to an empty string, so you get just .txt as the filename.