小编sal*_*ace的帖子

使用 Bash 的惰性正则表达式

我正在尝试使用 Bash 的内置正则表达式函数仅匹配 HTML 标签中包含的文本:

string='<span class="circle"> </span>foo</span></span>'
regex='<span class="circle"> </span>(.+?)</span>'
[[ $string =~ $regex ]]
echo "${BASH_REMATCH[1]}"
Run Code Online (Sandbox Code Playgroud)

但比赛不断捕获foo</span>

互联网上充斥着 sed 和 grep 的例子,我在 Bash 自己的正则表达式上找不到太多文档。

bash regular-expression

4
推荐指数
1
解决办法
6954
查看次数

XRandR 脚本从命令行正确运行,作为 cron 作业失败

我在 Fedora 21 上运行 LXDE。我的脚本的目的是在两个显示器上扩展显示:

#!/bin/sh
xrandr --output VIRTUAL1 --off --output LVDS1 --mode 1440x900 --pos 1280x124 --rotate normal --output TV1 --off --output VGA1 --mode 1280x1024 --pos 0x0 --rotate normal
Run Code Online (Sandbox Code Playgroud)

这在终端窗口中运行没有问题,但作为 cron 作业而窒息。

从我的 cron 日志:
Jul 9 20:14:01 localhost CROND[19494]: (user) CMD (/home/user/screens.sh)
Jul 9 20:14:01 localhost CROND[19492]: (user) CMDOUT (无法打开显示)

cron xrandr lxde

3
推荐指数
1
解决办法
1383
查看次数

标签 统计

bash ×1

cron ×1

lxde ×1

regular-expression ×1

xrandr ×1