linux – 相当于sh -e的perl

在/ bin / sh和/ bin / bash(我猜很多其他 shell),用#!/ bin / sh -e启动脚本(或在脚本中的某个位置执行set -e)会导致脚本中止当脚本中的任何命令行以状态代码不为0退出时.

是否有任何等效或解决方法在perl脚本中获得相同的行为? (即,如果任何指令生成错误或者使用系统执行任何外部命令(…)或反引号返回错误代码,则立即退出)

解决方法

看看 autodie核心模块.这将取代像open和fork这样的函数,这些函数会在失败时死掉.要使其与系统一起使用,您需要导入:all或:system,因为认情况下不会这样做.
use strict;   #always!
use warnings; #always!
use autodie qw(:system);

system('/bin/false'); #This will die
print "This will never be printed\n";

重要的是要注意,对于使用系统的autodie,您需要IPC :: System :: Simple模块.使用CPAN安装它,或者在Ubuntu上安装apt-get install libipc-system-simple-perl.

相关文章

Linux中的ARP防火墙主要用于防御ARP欺骗攻击,其效果取决于多...
insmod和modprobe加-f参数导致Invalid module format错误 这...
将ArchLinux安装到U盘 几个月前入门Arch的时候上网搜了不少安...
1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...