shell_script.sh:它有函数定义,当从Perl脚本调用时,它将以批处理模式在Linux上执行某些命令.
perl_script.pl:它具有要实现的代码和逻辑,用于调用等.
shell_script.sh文件的内容如下:
bash-4.2$cat shell_script.sh#!/bin/bash# Function DeFinitionsfunc_1 (){ echo "function deFinition"}func_2 (){ echo "function deFinition"}
perl_script.pl文件的内容如下:
bash-4.2$cat perl_script.pl#!/usr/bin/perluse Getopt::Long;my $var1;my $var1;Getoptions("var1=s" => $var1,"var2=s" => $var2,"help|?" => $help );if ($help){ HelpMenu();}print " Can I call the func_1 (defined in shell script) with arguments here..?? (in this perl script)";
我怎样才能在perl脚本perl_script.pl中调用函数func_1()(在shell_script.sh中定义)?
解决方法 要调用shell函数,shell需要知道它的定义.实现这一目标的一种方法是让shell首先获取定义函数的文件.然后,在不退出shell的情况下,调用该函数.从Perl脚本,例如:system 'bash','-c','source shell_script.sh; func_1';总结
以上是内存溢出为你收集整理的linux – 如何在Perl脚本中调用函数(在shell脚本中定义)全部内容,希望文章能够帮你解决linux – 如何在Perl脚本中调用函数(在shell脚本中定义)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)