Well I would do the following:

  • put the shell lines in a script and assure that they work!
  • use the shell that perl is going to use, or call explicitly /bin/tcsh or whatever
  • once you have something working, if it is short just use the rule {cmd => sh -c 'cmd1', where cmd1 is cmd in which ' => '\''}

    @cmd = ( q{/bin/tcsh}, "-c", ...); system(@cmd) == 0 or warn;

    Also the construct 'echo-like "..." | sh' to send commands to the shell seems ugly, just use perl to generate the necessary shell script, and execute it

    A small example to make things clearer, I hope.

    % steph@ape (/home/stephan/t2) % % ls -1 bag'cmds driver.pl more cmds % steph@ape (/home/stephan/t2) % % cat $'bag\'cmds' echo just another shell hacker echo just another perl hacker % steph@ape (/home/stephan/t2) % % cat 'more cmds' echo .done % steph@ape (/home/stephan/t2) % % cat driver.pl #!/bin/perl use strict; use warnings; $|++; use Data::Dumper; # make this line after the q op. valid shell my $main_cmd = q{ cat bag\'cmds "more cmds" | sh }; my @cmd = ( '/bin/ksh', '-c', $main_cmd ); print Dumper(\@cmd); print "\n./bin/sh -c '/bin/ksh -c ...'\n"; system(@cmd) == 0 or warn; print "\n.directly: at the mercy of your system shell\n ->"; system('echo $0') == 0 or warn; print "\n"; system($main_cmd) == 0 or warn; print "\n.generating script\n"; my $cmd_file = qq{temp$$.sh}; open my $outh, '>', $cmd_file or die; print $outh <<"EOSHELL"; $main_cmd EOSHELL system('cat', '-evnt', $cmd_file) == 0 or warn; system('/bin/ksh', $cmd_file) == 0 or warn; unlink $cmd_file; __END__ % steph@ape (/home/stephan/t2) % % perl driver.pl $VAR1 = [ '/bin/ksh', '-c', ' cat bag\\\'cmds "more cmds" | sh ' ]; ./bin/sh -c '/bin/ksh -c ...' just another shell hacker just another perl hacker .done .directly: at the mercy of your system shell ->sh just another shell hacker just another perl hacker .done .generating script 1 $ 2 cat bag\'cmds "more cmds" | sh$ 3 $ just another shell hacker just another perl hacker .done
    cheers --stephan

    In reply to Re: Unable to get a tcshell command line working in PERL v5 system command by sgt
    in thread Unable to get a tcshell command line working in PERL v5 system command by SteveC

    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.