Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!sgi!shinobu!odin!thestepchild!rhartman From: rhartman@thestepchild.sgi.com (Robert Hartman) Newsgroups: comp.unix.shell Subject: Re: Help with this script Message-ID: <1991Apr10.224050.17750@odin.corp.sgi.com> Date: 10 Apr 91 22:40:50 GMT References: <1991Apr9.164257.9128@agate.berkeley.edu> <1991Apr9.175008.12044@leland.Stanford.EDU> <1991Apr10.140153.480@cca.vu.nl> Sender: news@odin.corp.sgi.com (Net News) Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 42 In article <1991Apr10.140153.480@cca.vu.nl> hendrik@cca.vu.nl (Hendrik te Winkel) writes: > >> cd `find . -name -type d -print` > >Not really, again when you put this into a file it will change your >directory but after the filescript finishes you'll discover >that you are again in the original directory. >Of course you could alias it in csh. >But now some real answer from a guru please! Is it really impossible >to change your working dir with a shell script _and_ to remain there >after it is finished? I don't know how to do it. Please inform. > >Hendrik I'm not a guru, but I already posted answers to this. I'll summarize one last time. If you want the current shell to execute a script, you have to tell it to specifically. If you simply invoke a script on the command line, that script runs in a child process--same as any other command. To get the current shell to execute commands from a file (other than the tty): 1. Use the "." command to tell the shell to execute commands from the file given as its argument. 2. Make the script into a shell function. 3. Define a shell function that uses the "." command to interpolate the text of an existing script: ncd() { . $HOME/bin/ncd } 4. Or, if you can do the job with a one-liner, just do it: ncd() { cd `find . -name "*${1}*" -type d -print` ; pwd } Try it! -r