Re: Korn Shell conundrum

From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 05/11/05

  • Next message: Chris F.A. Johnson: "Re: Bash - conditional deletion of files"
    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>
    

  • Next message: Chris F.A. Johnson: "Re: Bash - conditional deletion of files"

    Relevant Pages

    • starting programs as a daemon
      ... init as parent process and no tty) which works in all linux distributions? ... I've written an init script which starts several other programs. ...
      (comp.os.linux.misc)
    • Re: restart network without shutdown
      ... Screen will allow the script to complete, whereas your ssh session is killing it half/part way through... ... Processes which start from within screen don't get killed, because, screen, the parent process, is still running. ...
      (freebsd-questions)
    • Korn Shell conundrum
      ... that directory once the script has executed. ... Script "gothere" contains something like: ... The parent process will remain in its current working directory. ... needs to check several arguments that can be passed in to it, and exit ...
      (comp.unix.shell)
    • Re: killing a script
      ... code level rather than the Control-C level. ... could put one line at the top of the script and be done with it. ... is completely invisible to the parent process. ...
      (comp.lang.python)
    • Re: Exit status of process by PID
      ... The exit status is only reported to the parent process, ... Since his script IS the parent, why would that be a problem? ... Barry Margolin, barmar@xxxxxxxxxxxx ...
      (comp.unix.shell)