in reply to Re^3: Heredoc with system call
in thread Heredoc with system call

Thanks for the suggestion but I am not very familiar with Perl so not really able to comprehend your answer and resolve my case. Basically I have to run a "cp $source $dest" command after logging-in as a different user(ABU) using "sudo su - ABU". The $source and $dest is something that I formulate in my perl script above but I am unable to pass it to the shell command I fork. Code(working snippet): ----
print "I want to copy $source to $dest after logging-in as ABU"; open my $fh, "|-", "sudo su - ABU" or die "can't run sudo: $?"; print $fh <<_EOF_; echo 'Logged-in as ABU' ls _EOF_ close $fh;
The only problem is to run "cp $source $dest" on the next line soon after the "ls" command. But I am not sure how to pass these arguments ?

Replies are listed 'Best First'.
Re^5: Heredoc with system call
by bliako (Abbot) on Apr 22, 2019 at 18:03 UTC

    In the code you just posted you have removed the single-quotes around _EOF_. This will prompt Perl to interpolate any perl-looking variable (for example a word prepended by sigils: $ or @ etc.) within the heredoc content. But now you have none. Try adding, in a new line, echo "i will cp '$source' '$dest'" and see what happens.

    Note: in your posts, please enclose all code within <c> ... </c> tags because most of us in here are humans, not machines.