From: felix@... Date: 2002-03-08T13:53:14+09:00 Subject: Re: Permanently change directory after exit >>In article <000201c1c649$31a20ae0$cbfbc9c8@guara>, "Guaracy Monteiro" writes: > I need change a path inside a script and stay there > after exit (without pipes etc). Can i do it? > e.g. > before: > /home/user > script: > #!/usr/local/bin/ruby > Dir.chdir('/usr/local/doc') > after: > /usr/local/doc Nope. When I first wanted to do this, it was very frustrating until I understood why. When a program runs, it is because some other program (the shell or a window manager) has spawbned it as a child process. There is no way for the child to tell the parent to change the parent's working directory. This is also why the child cannot change the parent's environment variables. But there is a convoluted way of doing this, at least from a shell, which may not be useful to you. In sh or bash or ksh, "source" a shell script with the '.' command, and it executes in the shell's environment. Then this new script would look like cd /usr/local/doc -- just that one line, you don't need the #! first line for a dot command. Call the script "mycd", run it as ". ~/mycd" and the shell will be in a different dir. But it won't be a ruby script. I don't rhink you can do that easily, unless you are running a ruby shell. I am just learning Ruby, so I am going to suggest some psuedo-Ruby here, which might work. Might not. Probably needs some tweaking if it could work! mycd.rb: #!/usr/bin/ruby Dir.chdir('/usr/local/doc') kernel.exec('/bin/sh') mycd: exec mycd.rb And from the command line: . mycd Pretty awkward. The shell sources a single line shell script (instead of running it as a child process) which replaces the shell with the ruby script. This changes the working directory, then replaces the ruby interpreter with a shell again. Any environment changes from the original shell might not carry into the ultimate replacement shell. -- ... _._. ._ ._. . _._. ._. ___ .__ ._. . .__. ._ .. ._. Felix Finch: scarecrow repairman & rocket surgeon / felix@crowfix.com GPG = E987 4493 C860 246C 3B1E 6477 7838 76E9 182E 8151 ITAR license #4933 I've found a solution to Fermat's Last Theorem but I see I've run out of room o