wrong $PATH variable when spawn a new process

29 views
Skip to first unread message

Peter Cheung

unread,
Aug 30, 2015, 12:59:25 AM8/30/15
to nodejs
Hi All

var commandStart='echo $0;cd '+self.item.dir;
var command=';make '+self.item.name;
var commandEnd='';
var child = spawn(xtermPath, ['-geo', '160x60-10-500', '-hold', '-e', '/bin/bash -x -c -i "echo $PATH"']);

It prints the wrong $PATH variable that i have set in .bashrc, why?

I saw bash has read my .bashrc by using verbose mode, take a look the image, but the .bashrc just can't take any effect.


thanks
from Peter
bash.png

Jimb Esser

unread,
Sep 4, 2015, 1:38:18 PM9/4/15
to nodejs
This likely has nothing to do with Node, but my guess is that whatever program "xtermPath" points to is executing the string passed to -e by passing it to bash, which, as a non-interactive invocation probably isn't loading .bashrc in the same way (I see you have -i to your own invocation...), and it is evaluating $PATH there, and then it is passing the already evaluated string to "/bin/bash -x -c -i", which is the one you're seeing exporting the path, but it has already been evaluated at that point.  Try, instead of "echo $PATH", executing a one-line shell script that does the same, and see if the behavior changes.  Alternatively, if you expect your path modification to work generally instead of just in an interactive shell, put it in a more appropriate place (although I did think that .bashrc was the right place for this, but it depends on OS and various other configuration options...).

Hope this helps!
  Jimb Esser
Reply all
Reply to author
Forward
0 new messages