bash - 如何将 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
我应该修改什么以便它接受变量?
解决方案
推荐阅读
- reactjs - 如何重新渲染低优先级的重型 React 组件?
- slack - 我们如何在 Slack 中设置群聊主题
- ios - SwiftUI:TextField 中的多色文本
- powerbi - 如果单击另一个表的任何行,如何过滤一个表
- php - 重新分配对象变量是否会破坏对象(例如 mysqli)?
- javascript - 为什么 ''classList.add()'' 方法在我的 Vuetify 应用程序中不起作用?
- python - 根据第二个过滤数据帧的结果过滤条件数据帧:寻求效率提升
- powerbi - 按非字母数字字符过滤字符串
- forms - 表单验证会破坏小部件对齐
- javascript - NodeJS,SocketIO IO发出功能不起作用