can we source a shell script in perl script

前端 未结 7 840
隐瞒了意图╮
隐瞒了意图╮ 2021-01-15 04:54

can we source a shell script in the perl script??

Example: Program 1:

cat test1.sh
#!/bin/ksh
DATE=/bin/date

program 2:

<         


        
7条回答
  •  青春惊慌失措
    2021-01-15 05:30

    Uhm.. is the below cheating?

    #!/bin/sh
    . ./test1.sh # source the test script
    echo Bash says $DATE
    export DATE;      # KEY to have the below Perl bit see $ENV{DATE}
    perl <<'ENDPERL';
        print "Perl says $ENV{DATE}\n";
    ENDPERL
    

    The problem is that sourcing the sh file may do whatever, and not just assign value X to variable Y...

提交回复
热议问题