I have tried this command in bash linux
JavaScript
x
echo "example=value" | sed "s/^example=(.*)$/1/"
The output is value
. But if I put it in a variable, it doesn’t work.
For example:
JavaScript
var="example=value" | sed "s/^example=(.*)$/1/"
echo $var
The output is nothing. What wrong?
Advertisement
Answer
Do it like this:
JavaScript
var=$(echo example=value | sed "s/^example=(.*)$/1/")
echo $var