I'm trying to path a web address to a bash script run under cgi. I search a little and found this link. From what I understood, this line should separate the variable from it's value:
USERNAME=`echo "$QUERY_STRING" | sed -n 's/^.*username=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"
So, reading about sed, I have concluded that this line should be sufficient for my needs:
url='echo "$QUERY_STRING" | sed "s/url=\(.*\)/\1/"'
where the input is
url=www.web.address.com
However, the variable get is the string is:
echo "$QUERY_STRING" | sed "s/url=(.*)/\1/" if I tried to remove the apostrophes I get an empty variable. Note that if I simply to the
echocommand I the desired effect.
How can I separate the url value?
You can use parameter expansion and you won't need sed.
echo "${QUERY_STRING##*=}"
To set a variable to that value:
url=${QUERY_STRING##*=}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With