Re: Korn Shell conundrum
From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 05/11/05
- Previous message: Heiner Steven: "Re: Using ":" as a command line argument"
- In reply to: tony.alldis_at_crapmail.com: "Korn Shell conundrum"
- Next in thread: Stephane CHAZELAS: "Re: Korn Shell conundrum"
- Reply: Stephane CHAZELAS: "Re: Korn Shell conundrum"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 11 May 2005 17:24:19 -0400
On Wed, 11 May 2005 at 21:01 GMT, tony.alldis@crapmail.com 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 ]
> then
> cd $1
> else
> print "Directory doesn't exist"
> exit 1
> fi
>
> 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>
- Previous message: Heiner Steven: "Re: Using ":" as a command line argument"
- In reply to: tony.alldis_at_crapmail.com: "Korn Shell conundrum"
- Next in thread: Stephane CHAZELAS: "Re: Korn Shell conundrum"
- Reply: Stephane CHAZELAS: "Re: Korn Shell conundrum"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|