What I was attempting to do is exec $conn and pass $instance[$selection] as the parameter. [edited for readability]

Well, you'd need quotes around the whole thing then:

exec "$conn $instance[$selection]"

But it still won't do what you want. The real issue is how the shell uses subprocesses. The actual login shell is executing the .profile, so you could write your menuing code directly into it for the affect you want.

When you spawn perl (or even another shell script,) however, it's a completely different process with its own environment. When you call exec with a single string argument like that, it starts a subshell. You can source a file in that subshell using the shell builtin "." but the results of it won't make it back into the parent (login) shell.

A way around it, if you really feel you must use perl, might be to have perl print the appropriate shell commands and then, in the .profile, you might exec the output that perl gives you. One way or the other though, you've got to either get the login shell to set the environment for you or you have to replace the login shell with another shell that sets the environment appropriately. Both of those options amount to the same thing.

Update: The reply by graff below shows another way of getting the shell to use perl's output to set its own environment. It's a fine solution.

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Re: Re: Unexpected die by sauoq
in thread Unexpected die by peschkaj

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.