我试图通过 bash 脚本将 malloc 的值更改为 1234m,但没有看到任何更改。我认为这是我的正则表达式的问题,有人能看到我做错了什么吗?
字符串
DAEMON_OPTS="-a :6081 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
代码
# get the memory allocation
echo "Enter the memory allocation"
read malloc
# update the default config
sed -ie 's/malloc,.*[0-9m]$/malloc,'$malloc'/gI' /etc/default/varnish
最佳答案
您在 sed 模式中的 $
之前缺少一个 "
。
顺便说一句,您的模式有效,但方式可能与您预期的不同:字符类 [0-9m]
仅匹配一个字符,m
这个案例。该号码正在与 .*
匹配。更好的模式可能是 malloc,[0-9]\+m"$
。
关于regex - 使用 sed 更改配置的 Bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12856229/