Help with this script
Robert Hartman
rhartman at thestepchild.sgi.com
Thu Apr 11 08:40:50 AEST 1991
In article <1991Apr10.140153.480 at cca.vu.nl> hendrik at cca.vu.nl (Hendrik te Winkel) writes:
>
>> cd `find . -name <argument> -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
More information about the Comp.unix.shell
mailing list