I was wondering if anyone here has some bright ideas on how to (tempurary) change a shell from within a Perl script without the script actually "end"! I mean, say I do "system ("bash");", the script won't continue until I do "exit" in that newly opened bash shell. Is it even possible?
Indeed this is what system should do in the first place. Did you try it? Or do you want to do something different?
[blazar@zion blazar]$ perl -le 'print 1; system "bash"; print 2' 1 [blazar@zion blazar]$ whoami blazar [blazar@zion blazar]$ exit 2 [blazar@zion blazar]$
Ah, yea, and how to figure out _what_ shell I'm currently in?
Well, it depends on what you mean exactly with "shell I'm currently in". If the perl script is launched from a shell, and thus is a child of it, then it can check the cmdline of the parent process. Is this what that you want?

In reply to Re: Change shell within Perl by blazar
in thread Change shell within Perl by Ace128

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.