I have tried this command in bash linux
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:
var="example=value" | sed "s/^example=(.*)$/1/" echo $var
The output is nothing. What wrong?
Advertisement
Answer
Do it like this:
var=$(echo example=value | sed "s/^example=(.*)$/1/") echo $var