Shell script change directory with variable

You variable contains a carriage return. Try saying:

cd $(echo $RED_INSTANCE_NAME | tr -d '\r')

and it should work. In order to remove the CR from the variable you can say:

RED_INSTANCE_NAME=$(echo $RED_INSTANCE_NAME | tr -d '\r')

The following would illustrate the issue:

$ mkdir abc
$ foo=abc$'\r'
$ echo "${foo}"
abc
$ cd "${foo}"
: No such file or directory
$ echo $foo | od -x
0000000 6261 0d63 000a
0000005
$ echo $foo | tr -d '\r' | od -x
0000000 6261 0a63
0000004
$ echo $'\r' | od -x
0000000 0a0d
0000002

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)