How to use both pipes and prevent shell expansion in perl system function?

前端 未结 2 1492
温柔的废话
温柔的废话 2021-01-29 08:38

If multiple arguments are passed to perl\'s system function then the shell expansion will not work:

# COMMAND
$ perl -e \'my $s=\"*\"; system(\"echo\", \"$s\" )\         


        
2条回答
  •  独厮守ぢ
    2021-01-29 08:53

    You can use open to pipe directly to mailx, without your content being interpreted by the shell:

    open( my $mail, "|-", "mailx", "-s", $email_subject, $recipient );
    say $mail $email_message;
    close $mail;
    

    More details can be found in open section of perlipc.

提交回复
热议问题