0

Why sed interprets the filename given in the variable wrong? (/etc/postgresql/9.6/main/postgresql.conf interpreted as esql/9.6/main/postgresql.conf)

script:

#!/bin/bash
set -ex
...
echo "$psql_config_file"
${ssh_login} sudo -Hiu postgres sed -i 's/[#]*wal_level\ =.*#/wal_level\ =\ archive\ #/g' "$psql_config_file"

output:

+ echo $'/etc/postgresql/9.6/main/postgresql.conf\r'
/etc/postgresql/9.6/main/postgresql.conf
+ ssh -t user@192.168.42.133 sudo -Hiu postgres sed -i 's/[#]*wal_level\=.*#/wal_level\ =\ archive\ #/g' $'/etc/postgresql/9.6/main/postgresql.conf\r'
: No such file or directoryesql/9.6/main/postgresql.conf
micha
  • 65
  • 11
  • 1
    Because it has an extra `\r` (aka `^M`, aka `CR`) at the end. Probably because somewhere you have a file with DOS line endings and are using that to set the variable containing the file name. – jas Oct 14 '18 at 20:48
  • The `$'\r'` is right there in the `set -x` log. See the **very first thing** in the "before asking about problematic code" section at https://stackoverflow.com/tags/bash/info – Charles Duffy Oct 14 '18 at 20:58

0 Answers0