> -----Original Message-----
> From: THE SPENCERS [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 05, 2001 9:15 PM
> To: [EMAIL PROTECTED]
> Subject: CHDIR
> 
> 
> Hello Team,
> 
>       Let me just start my saying I am a very big fan of PERL and this
> mailing
> list.  I have been reading from the list for about 5 months 
> now and WOW!
> what great help you people are!!!!
> 
>      I would like to know is there anyway to physically move 
> to a directory
> running a Perl script?  What I would like to create just for 
> fun is a menu
> directory on my Linux box that gives me a list of directories 
> to choose from
> and once a choose from the list (e.g.   (1) Perl directory) 
> the script drops
>                                                               
>   (2) Bash
> directory
>                                                               
>   (3) Music
> directory
> 
> me off in that directory to play around in .
> 
>       I know the command CD is a shell built-in and this may 
> or may not be
> where
> my problem is.   I have tried using the Function CHDIR and by 
> using it I can
> do anything inside a certain directory I wish except be  drop 
> off in it.
> 
>  Any help would be great!

(This is really a Unix/shell question rather than a Perl question)

A Perl script (or any script/program) will run in a child process 
of your shell, and a child process cannot affect the environment 
of the parent process.

Two ways of doing this that I can think of:

1. Source a shell script that calls your perl menu. Have your
perl menu output the directory to change to and have your shell
script change directories. You will have to invoke your shell
script like:

   $ . menu.sh         # Bourne-like shells

menu.sh would look something like

   cd `menu.pl`

2. Have your perl menu chdir() and then exec() another shell.
Something like this:

   #!/usr/bin/perl
   chdir '/etc/';
   exec $ENV{SHELL};

You will have to invoke your perl menu with the shell's exec
command:

   $ exec menu.pl

If you don't, you'll still get a new shell in the new directory,
but the parent shell will still be around.

I would say sourcing a shell script is the way to go.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

  • CHDIR THE SPENCERS
    • Bob Showalter

Reply via email to