I wrote the following shell script for a pg backup:#!/bin/bashPG_USER=donatoDATABASE=mydbSERVER=216.58.219.174DIR=$HOME/pg_bakDATE=$(date +%m_%d_%y)FILE=$DATABASE_$DATEERROR_FILE=$HOME/pg_bak/error_bak/$FILE_error.txt# pass @ .pgpassPG_BAK_NOW () {  pg_dump -h $SERVER -U $PG_USER $DATABASE >$FILE 2>$ERROR_FILE  code=$?  if [ $code -ne 0 ]; then    echo 1>&2 The backup failed (exit code $code), check for errors in $ERROR_FILE  fi}echo Ready to dump to $FILE >> $HOME/pg_status cd $DIRif [ -f $FILE ];then  rm $FILE  PG_BAK_NOW else  PG_BAK_NOWfiWhen I execute it, I know it executes for a bit of time:$ pgrep -fl pg_bak.sh4603 pg_bak.shBut then it does crash:$ ./pg_bak.shThe backup failed (exit code 1), check for errors in /home/viggy/pg_bak/error_bak/.txtNotice the .txt part. The name of the error file was supposed to be mydb_6_11_2016_error.txt, not .txt. Why did the bash script not interpolate the variable $FILE and the hardcoded string _error? It did interpolate $FILE in the dump file correctly, but not the error file. Why? 
variable interpolation in shell script
bash;shell script
A very common mistake:ERROR_FILE=$HOME/pg_bak/error_bak/${FILE}_error.txt