views:

2009

answers:

5

I wanted to use the Python installed under cygwin rather than one installed under WinXP directly, so I edited ~/.bashrc and sourced it. Nothing changed. I tried other things, but nothing I did changed $PATH in any way. So I rebooted. Aha; now $PATH has changed to what I wanted.

But, can anyone explain WHY this happened? When do changes to the environment (and its variables) made via cygwin (and bash) take effect only after a reboot?

(Is this any way to run a railroad?) (This question is unlikely to win any points, but I'm curious, and I'm also tired of wading through docs which don't help on this point.)

A: 

You may need to re-initialize bash's hashes after modifying the path variable:

hash -r
Ross Rogers
bash's hashes? Hmmm. Memories of 'rehash' on a Sun 3. IIRC. But I thought 'source .bashrc' took care of that, no?
behindthefall
rehash is tcsh. hash -r is for bash
Ross Rogers
+2  A: 

Try:

PATH="${PATH}:${PYTHON}"; export PATH

Or:

export PATH="${PATH}:${PYTHON}"

the quotes preserve the spaces and newlines that you don't have in your directory names. I repeat "don't".

If you want to change the path for the current environment and any subsequent processes, use something similar to either of the commands above; they are equivalent.

If you want to change the path for the next time you start Bash, edit ~/.bashrc and add one of the above (for example) or edit the existing PATH setting command that you find there.

If you want to affect both the current environment and any subsequent ones (i.e. have an immediate and a "permanent" affect), edit ~/.bashrc and do one of the following: type one of the first two forms shown above or source the ~/.bashrc file. Sometimes, you may not want to do the sourcing if, for example, it would undo some temporary thing that you're making use of currently like have some other variables set differently than ~/.bashrc would set (reset) them to.

I don't think you need to worry about hash unless you're either doing some serious rearranging or adding some local replacements for system utilities perhaps.

Dennis Williamson
Well, if I needed any more proof, this shows how ill at ease I am with bash. What do I have to do? source, hash AND export all the time in that order?
behindthefall
You've lost me. I'm to preserve whitespace that's not there? Or are you saying, "Stick with *NIX naming conventions"? (Which I always do; I have a horror of whitespace in filesystem names --- don't even like hyphens.)
behindthefall
On my cygwin system, to modify $PATH in the current shell session, I needed to perform the second form of the command. So, if you add the `export PATH="${PATH}:{$PYTHON}"` to your .bashrc, it should work every time you log in.
Tim Henigan
Preserve the whitespace *in case* it's there (but don't put any there yourself **ever**).
Dennis Williamson
@Tim: The first form of the command assumes that you've set the variable separately. I'm editing my answer to make it a little clearer.
Dennis Williamson
@behindthefall: See my revised answer to hopefully clear up what to do when.
Dennis Williamson
+2  A: 

If you want your changes to be permanent, you should modify the proper file (.bashrc in this case) and perform ONE of the following actions:

  • Restart the cygwin window
  • source .bashrc (This should work, even if is not working for you)
  • . .bashrc (that is dot <space> <filename>)

However, .bashrc is used by default when using a BASH shell, so if you are using another shell (csh, ksh, zsh, etc) then your changes will not be reflected by modifying .bashrc.

Freddy
The above, noting that ". .bashrc" is a bash shorthand for "source .bashrc"
Marcus Griep
A: 

A couple of things to try and rule out at least:

  1. Do you get the same behavior as the following from the shell? (Pasted from my cygwin, which works as expected.)

    $ echo $PATH
    /usr/local/bin:/usr/bin:/bin
    
    
    $ export PATH=$PATH:/cygdrive/c/python/bin
    
    
    $ echo $PATH
    /usr/local/bin:/usr/bin:/bin:/cygdrive/c/python/bin
    
  2. Is your bashrc setting the PATH in a similar way to the above? (i.e. the second command).

  3. Does your bashrc contain a "source" or "." command anywhere? (Maybe it's sourcing another file which overwrites your PATH variable.)

ars
Hello again, ars. I'm done for the night, but shall try again tomorrow. Thanks.
behindthefall
A: 

I've never used `hash', except I think I executed it once in 1997, and I think I haven't encountered the problem it's supposed to prevent.

spicetrader