Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Is it possible to change the directory of the parent process on Linux?

by bliako (Monsignor)
on Mar 10, 2021 at 14:34 UTC ( [id://11129408]=note: print w/replies, xml ) Need Help??


in reply to Is it possible to change the directory of the parent process on Linux?

Unlikely but if your parent process is a unix shell and you want to end it as soon as the perl script ends, then end your perl script with exec '/bin/bash --ini-file somefile' and somefile contains cd /. You can do without the file by hacking something like this: bash$ /bin/bash --init-file <(echo "cd/"). In this way you will end up with a new shell and in dir /

Replies are listed 'Best First'.
Re^2: Is it possible to change the directory of the parent process on Linux?
by Anonymous Monk on Mar 10, 2021 at 15:40 UTC
    Yes, this orders the shell to *replace itself* ("exec ...") with another one ... which might do more changes than you want, such as losing environment-variable settings that are not made by .bashrc. Another common way to do it is to simply put the command which invokes the Perl script into a "two-liner" command-file which ends with a cd command. The Perl script is run, then the current-directory is changed, then the command-file ends, and you're still in the same shell instance.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129408]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-25 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found