Re: Korn Shell conundrum
From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: Wed, 11 May 2005 17:24:19 -0400
On Wed, 11 May 2005 at 21:01 GMT, firstname.lastname@example.org wrote:
> Hi I wonder if someone might be able to help me as I'm going nuts
> trying to figure this one out!
> I need to be able to cd to a directory, and leave the parent process in
> that directory once the script has executed.
There is no way, other than sourcing the file or putting the
script in a function.
> I know this can be done like this...
> Script "gothere" contains something like:
> cd /var
> Run from the command line if run like this:
> $ gothere
> The parent process will remain in its current working directory.
> If run like this:
> $ . gothere
> The parent process will have cd'd to the /var directory.
> All well and good up to this point.
> Now, if the script needs to carry out some checking such as a variable
> being passed to it like so:
> if [ -d $1 ]
> cd $1
> print "Directory doesn't exist"
> exit 1
> If this is run using the "." to run in the context of the parent
> process, it will work ok, otherwise it will end up logging out the
> parent due to the exit!
Use return instead of exit.
-- Chris F.A. Johnson <http://cfaj.freeshell.org> ================================================================== Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress <http://www.torfree.net/~chris/books/ssr.html>