in reply to Unable to get a tcshell command line working in PERL v5 system command

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