I hope someone can help me here. I'm trying to assign the output of a grep command to a variable in a bash script and the variable comes up empty. When I run the following:el_value=$(grep '<$2>.*<$2>' $1 | sed -e 's/^.*<$2/<$2/' | cut -f2 -d'>'| cut -f1 -d':')echo DEBUG: The value of el_value is '$el_value'The output is:DEBUG: The value of el_value is ''If I run the grep command outside of the script (and substitute the variables for real values) I get the output I'm expecting.Sorry, I guess you need a little more information than that. Here is a snippet of script. Use this script and add the values listed above.#!/bin/bashif [ $# -ne 3 ]; thenecho 1>&2 'This script replaces xml elements value with the one provided as a command parameter \n\n\tUsage: $0 <xml filename> <element name> <new value>'exit 127fiel_value=`grep <$2>.*<$2> $1 | sed -e s/^.*<$2/<$2/ | cut -f2 -d'>'| cut -f1 -d':'`echo DEBUG: The value of el_value is '$el_value'
Help with assigning output of grep to a variable
linux;bash