Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^2: source a file in Linux using perl script

by salva (Canon)
on Nov 30, 2020 at 09:23 UTC ( #11124389=note: print w/replies, xml ) Need Help??

in reply to Re: source a file in Linux using perl script
in thread source a file in Linux using perl script

#!/usr/bin/perl use POSIX; use String::ShellQuote qw(shell_quote); unless (defined $ENV{CTC_HOME}) { $ENV{DONT_LOOP_FOREVER}++ or die "infinite loop detected"; exec "source ~/.bash_profile && ".shell_quote($^X, $0, @ARGV); POSIX::_exit(255); } chdir($ENV{CTC_HOME}); ...

Though, I have to admit I prefer the simpler shell wrapper solution given by Corion.

Replies are listed 'Best First'.
Re^3: source a file in Linux using perl script
by Corion (Patriarch) on Nov 30, 2020 at 09:50 UTC

    I think the one drawback of re-executing yourself like that is that you lose Perl command line switches like -Ilib etc. ... There is Devel::PL_origargv, which gives you the original command line, but I'm not sure that I would want to go such an esoteric length when a shell script can do the same.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2022-01-24 13:35 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (64 votes). Check out past polls.