Your code works fine, the problem is that your file is saved on Windows where lines end with \r\n
instead of Unix \n
.
You can tell because of the weird, trailing 2015
in the error message. It got there because the tool intended to write out a message like:
psql: failed: /etc/bkpdb/04-03-2015\r.sql: No such file or directory
But due to the carriage return \r
, the cursor moves to the start of the column, and starts overwriting the start of the message:
p̶s̶q̶l̶:̶ ̶f̶a̶i̶l̶e̶d̶:̶ ̶/̶e̶t̶c̶/̶b̶k̶p̶d̶b̶/̶0̶4̶-̶0̶3̶-2015
.sql: No such file or directory
You're therefore left with:
.sql: No such file or directory2015
To solve this, just convert your file from Windows/DOS format to Unix, either in your text editor or with dos2unix
, fromdos
or tr -d '\r'
. Here's trouble shooting step #1 from the bash tag wiki:
Check whether your script or data has DOS style end-of-line characters
Use cat -v yourfile
or echo "$yourvariable" | cat -v
.
DOS carriage returns will show up as ^M
after each line.
If you find them, delete them using dos2unix
(a.k.a. fromdos
) or tr -d '\r'