If you mean that you want a csh environment variable called "data_root" to be set to some value, and you want your third system call to cause that value to be echoed to stdout, then...

Well, first, merlyn is right, of course, that's a separate shell process from the first two, and so it doesn't know anything about what happened in the previous system calls. On top of that, when you write a system call like this:

$status = system( "$program arg1 $arg2" );
perl interprets this to mean that there should be a perl scalar variable called "$arg2", and the value of this variable should be included as the third token in the command line being passed to system().

Just what are you really trying to accomplish, anyway? Why do you have backticks in the second system call? Why are you using csh at all??

Apropos of merlyn's comment about how you would need to have these three command lines run in the same shell invocation, here's a little trick you might keep in mind:

open( SH, "| /bin/csh" ) or die "Can't start subshell: $!"; print SH "echo this is foo bar\n"; print SH "source some_script\n"; print SH "echo \$some_obscure_shell_variable_set_by_some_script\n"; #...

(Note the backslash in front of the "$", so perl knows that it isn't being used as part of a perl variable name.)

But really, whatever it is you're trying to do, there probably is a better way.


In reply to Re: Perl system calls in csh Not executing! by graff
in thread Perl system calls in csh Not executing! by Anonymous Monk

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.