首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Perl一行转成bash函数?

将Perl一行转成bash函数?
EN

Stack Overflow用户
提问于 2015-06-18 12:08:23
回答 1查看 364关注 0票数 0

有没有一种方法可以将perl一行变成bash函数?

代码语言:javascript
复制
#!/bin/bash
# ~/.bashrc:
stopwatch() {
   perl -wE 'for (reverse 1..(shift)-1) {system q!clear!;open FIGLET,q!|figlet -f banner -c!;printf FIGLET "%2d:%02d",$_/60,$_%60;sleep 1}' "$1"
}

source-ing ~/.bashrc抱怨如下:

  • 寻找匹配的‘’时的意料之外的EOF
  • 语法错误接近意外标记“反向”
  • 以此类推。

当然,通常的壳包裹可以工作,但是这里我尝试让bash别名/函数调用珀尔

必须有一种无需创建全新*.pl文件的方法。非常感谢!

EN

回答 1

Stack Overflow用户

发布于 2015-06-18 12:39:00

您也可以尝试以这种方式一起运行bash和perl脚本。而且,在你的例子中,-E是我怀疑的地方。perl -e总是工作,但perl -E在perl 5.8.8中不工作。

参见将perl与bash相结合的代码。

代码语言:javascript
复制
#!/bin/bash
# bash_test
echo "bash commands that you wish to write"
exit 0
# End of Bash part of the script.
# =======================================================
#!/usr/bin/perl
# This part of the script must be invoked with -x option.
print "here you can use your simple system() or exec() that you might wish to use right?";
# End of Perl part of the script.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30914955

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档