1

I'm trying to change the value of malloc to say 1234m via a bash script but not seeing any changes. 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

3 Answers 3

3

You are missing a " before the $ in the sed pattern.

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. The number is being matched by .*. Better pattern might be malloc,[0-9]\+m"$.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked brilliantly, thanks! Can't believe I missed the m" at the end of the line!
1

Try this sed command:

On Mac:

sed -E 's/malloc,[0-9]+m/malloc,'$malloc'/' /etc/default/varnish

or on Linux:

sed -r 's/malloc,[0-9]+m/malloc,'$malloc'/' /etc/default/varnish

Comments

0

The following sed line worked for me, enclosing it in " rather than ':

 sed -ie "s/malloc,[0-9]\+m$/malloc,$malloc/gI" /etc/default/varnish

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.