perl backticks: use bash instead of sh

前端 未结 6 1608
南笙
南笙 2021-01-05 11:20

I noticed that when I use backticks in perl the commands are executed using sh, not bash, giving me some problems.

How can I change that behavior so perl will use ba

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-05 12:05

    Create a perl subroutine:

    sub bash { return `cat << 'EOF' | /bin/bash\n$_[0]\nEOF\n`; }
    

    And use it like below:

    my $bash_cmd = 'paste filename <(cut -d " " -f 2 filename2 | grep -v mean) >> filename3';
    print &bash($bash_cmd);
    

    Or use perl here-doc for multi-line commands:

    $bash_cmd = <<'EOF';
        for (( i = 0; i < 10; i++ )); do
           echo "${i}"
        done
    EOF
    print &bash($bash_cmd);
    

提交回复
热议问题