Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

When I'm in one directory and echo path

pwd
/Users/me/src/some_proj

echo $PATH
/Users/me/.gem/ruby/2.0.0/bin:/opt/boxen/chruby/versions/2.0.0-
p353/lib/ruby/gems/2.0.0/bin:/opt/boxen/chruby/versions/2.0.0-
p353/bin:bin:/opt/boxen/chruby/bin:/opt/boxen/ruby-
build/bin:node_modules/.bin:/opt/boxen/nodenv/shims:/opt/boxen/nodenv/bin:
/opt/boxen/bin:/opt/boxen/homebrew/bin:/opt/boxen/homebrew/sbin:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin

When I'm in a different directory and echo path

pwd
/Users/me/src_personal/my_gems/som_gem

echo $PATH
bin:/opt/boxen/chruby/bin:/opt/boxen/ruby-build/bin:
node_modules/.bin:/opt/boxen/nodenv/shims:/opt/boxen/nodenv/bin:
/opt/boxen/bin:/opt/boxen/homebrew/bin:/opt/boxen/homebrew/sbin:
bin:/opt/boxen/chruby/bin:/opt/boxen/ruby-build/bin:
node_modules/.bin:/opt/boxen/nodenv/shims:/opt/boxen/nodenv/bin:
/opt/boxen/bin:/opt/boxen/homebrew/bin:/opt/boxen/homebrew/sbin:
bin:/opt/boxen/chruby/bin:/opt/boxen/ruby-build/bin:
node_modules/.bin:/opt/boxen/nodenv/shims:/opt/boxen/nodenv/bin:
/opt/boxen/bin:/opt/boxen/homebrew/bin:/opt/boxen/homebrew/sbin:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin

I get a different $PATH. I thought $PATH was a global variable in the shell that doesn't change. Why are these paths different in different directories?

share|improve this question
3  
It wouldn't changed automagically. Chances are that you executed a command/script inadvertently. –  devnull May 6 '14 at 6:02
1  
Does this change happen in a single logon session, under the same instance of the shell? Eg is the only difference between the two cases that the directory was changed using "cd"? If so, is the cd command aliased to something that could affect the PATH? –  Johan May 6 '14 at 9:54

1 Answer 1

There are no global variables in the shell, i.e. variables shared between different instances (processes). Exported variables are copied to child processes but from there, they are independent.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.