首页 > 解决方案 > 如何将 perl 命令中的变量用于 bash 脚本

问题描述

我有这个命令来查看日志的最后 10 分钟:

perl -MDate::Parse -ne 'print if/^(.{15})\s/&&str2time($1)>time-600' /path/log

现在我想把它放在一个脚本中,并把它放在一个变量而不是 600 中,以便能够更轻松地修改时间

#!/bin/bash
lasttime="600"
perl -MDate::Parse -ne 'print if/^(.{15})\s/&&str2time($1)>time-$lasttime' /path/log
# script does not end here. Run other commands like sed, grep etc. Why it should be in bash

但是屏幕上什么也没有出现。但是如果我删除变量它工作正常

#!/bin/bash
perl -MDate::Parse -ne 'print if/^(.{15})\s/&&str2time($1)>time-600' /path/log

我应该修改什么以便它接受变量?

标签: bashperl

解决方案


推荐阅读