【发布时间】:2016-10-22 11:17:04
【问题描述】:
我有以下我用 perl 编写的脚本,它工作得很好。但我正在尝试使用 bash 来实现同样的目标。
#!/usr/bin/perl
use 5.010;
use strict;
INIT {
my $string = 'Seconds_Behind_Master: 1';
my ($s) = ($string =~ /Seconds_Behind_Master: ([\d]+)/);
if ($s > 10) {
print "Too long... ${s}";
} else {
print "It's ok";
}
}
__END__
如何使用 bash 脚本实现这一点?基本上,我希望能够读取并匹配字符串“Seconds_Behind_Master: N”末尾的值,其中 N 可以是任何值。
【问题讨论】:
-
在
INIT块中运行代码似乎令人困惑和分心。如果它是您要翻译的块的内容,只需将其削减。另见minimal reproducible example -
tripleee,我想在 bash 中实现逻辑,因此在 perl 脚本中使用 init 并不那么重要。所以是的,请只关注内部代码内容。