[英]Bash script to change config using sed
I'm trying to change the value of malloc to say 1234m via a bash script but not seeing any changes. 我试图通过bash脚本将malloc的值更改为1234m,但没有看到任何更改。 I presume it is an issue with my regex, can anybody see what I've done inncorrectly?
我认为这是我的正则表达式的一个问题,任何人都可以看到我做的正确吗?
String 串
DAEMON_OPTS="-a :6081 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
Code 码
# 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
You are missing a "
before the $
in the sed pattern. 你错过了
"
在sed模式中的$
之前”。
By the way, your pattern works, but in a different way than you probably intended: the character class [0-9m]
matches just one character, m
in this case. 顺便说一下,你的模式有效,但方式与你想要的方式不同:字符类
[0-9m]
只匹配一个字符,在本例中为m
。 The number is being matched by .*
. 该号码与
.*
相匹配。 Better pattern might be malloc,[0-9]\\+m"$
. 更好的模式可能是
malloc,[0-9]\\+m"$
。
Try this sed command: 试试这个sed命令:
On Mac: 在Mac上:
sed -E 's/malloc,[0-9]+m/malloc,'$malloc'/' /etc/default/varnish
or on Linux: 或者在Linux上:
sed -r 's/malloc,[0-9]+m/malloc,'$malloc'/' /etc/default/varnish
以下sed
行为我工作,将其括在"
而不是'
:
sed -ie "s/malloc,[0-9]\+m$/malloc,$malloc/gI" /etc/default/varnish
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.