Bash – How to pass a string parameter on bash function

bashfunctionparameterstring

I have this code that does work:

get_parameter ()
{
   echo "$query" | sed -n 's/^.*name=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"
}

But I want to replace the "name" with the parameter that I pass to get_parameter

get_parameter ()
{
   echo "$query" | sed -n 's/^.*$1=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"
}
NAME=$( get_parameter name )

This however, doesn't work. Where am I wrong?

Best Answer

Quoting: In short, variables are not replaced with their values inside 'single-quoted' strings (aka. "variable substitution"). You need to use any one of "double quotes", $'dollar quotes', or

<<EOF
here strings
EOF
Related Question