1

I have a strange problem. I have a variable that I have exported in ~/.bashrc.

export NCARG_ROOT=/usr/local/ncl

In a terminal I can echo the variable, and it shows up correctly:

user@computer ~]$ echo $NCARG_ROOT
/usr/local/ncl

When I try to cd to it however, I get an error:

user@computer ~]$ cd $NCARG_ROOT
: No such file or directory.

The path (/usr/local/ncl) does indeed exist. It seems as though when the variable is executed it is empty to the shell (note that there should be something before the colon). Curiously a similar situation happens for the c-shell. I add the following line to the bottom of /etc/csh.cshrc and I get the same problem after switching shells:

setenv NCARG_ROOT /usr/local/ncl

changes shell

user@computer ~]$ cd $NCARG_ROOT
: No such file or directory

I have found a workaround. Adding the same export line to ~/.bash_profile seems to work. But by my understanding, this should work the way I originally had it, or am I missing something?

I am using Scientific Linux 6.10, which is a Red Hat Enterprise Linux rebuild.

  • Do you have an alias or shell function wrapping around `cd` that might interfere? Because I can't reproduce the error message with an empty or non-existent parameter, `cd ""` brings me to my home directory without any error. – Tanktalus Dec 02 '19 at 20:30
  • What does `declare -p NCARG_ROOT | cat -v` show? Is there a trailing `^M` carriage return? If so, your `.bashrc` has Windows line endings and needs to be converted to UNIX format. – John Kugelman Dec 02 '19 at 20:35
  • 2
    Note the error message; it should start `cd: ...`, not `: ...`. Your file has DOS line endings and `NCARG_ROOT` ends with a carriage return. – chepner Dec 02 '19 at 20:36
  • I checked the alias list and couldn't find any substitutes for `cd`. There is nothing wrapping around 'cd' that I am aware of. How could I check? – lpsupercell Dec 02 '19 at 20:38
  • That's got to be it. I copied and pasted into .bashrc from a text file generated with Windows when I first set this up. Didn't know that would be an issue. I will try to regenerate the file and add manually. Thanks! – lpsupercell Dec 02 '19 at 20:42
  • Update: I remade the .bashrc file from the backup in /etc/skel/ and this time manually inserted my additions. Works correctly now. – lpsupercell Dec 02 '19 at 20:57

0 Answers0