1

Yes, I know that I can run

. my_cd_script.sh

to change my directory directly. However, once I do that, my $PATH is messed up. For instance, when I type ls, the shell will return Command not found.

Anyone encountered this?

gniourf_gniourf
  • 44,650
  • 9
  • 93
  • 104
user1836155
  • 858
  • 14
  • 29
  • 4
    That could only happen if `my_cd_script.sh` is modifying the value of `PATH`. Simple answer is, don't do that. – chepner Apr 02 '15 at 16:16
  • 3
    The script probably uses the variable name `PATH` to store a path, clobbering the shell's search path. This is why scripts should [always use lowercase variable names](http://stackoverflow.com/questions/673055/correct-bash-and-shell-script-variable-capitalization). – that other guy Apr 02 '15 at 16:24
  • 2
    Paste your `my_cd_script.sh` script. – Etan Reisner Apr 02 '15 at 16:26
  • Seems like you guys are completely correct. I named a variable "path" without a second thought, although I would've expected shell to be case sensitive. Please post an explicit answer so that I can check-mark it. Thanks! – user1836155 Apr 02 '15 at 16:34
  • 1
    If you're running into variable names not seeming to be case-sensitive, then I suspect you're not actually using `bash`. Maybe `csh` instead, or some other variant in the `csh` family... – twalberg Apr 02 '15 at 16:47
  • I used the "#!/bin/bash" header though – user1836155 Apr 02 '15 at 16:52
  • 1
    The header means nothing when you source a file with `. myscript` - it's just a comment in that case. So what's the shell or script in which you did the sourcing running? – twalberg Apr 02 '15 at 17:19
  • Oh, in that case, definitely not bash. Thanks, that does clear things up! – user1836155 Apr 02 '15 at 19:22

1 Answers1

1

I named a variable "path" without a second thought, although I would've expected shell to be case sensitive. – user1836155

If you're running into variable names not seeming to be case-sensitive, then I suspect you're not actually using bash. Maybe csh instead, or some other variant in the csh family... – twalberg

I used the "#!/bin/bash" header though – user1836155

The header means nothing when you source a file with . myscript - it's just a comment in that case. – twalberg

Armali
  • 18,255
  • 14
  • 57
  • 171