Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing first letters in a string using bash under cgi

Tags:

string

bash

cgi

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 echo command I the desired effect.

How can I separate the url value?

like image 299
Yotam Avatar asked Feb 15 '26 17:02

Yotam


1 Answers

You can use parameter expansion and you won't need sed.

echo "${QUERY_STRING##*=}"

To set a variable to that value:

url=${QUERY_STRING##*=}
like image 85
Dennis Williamson Avatar answered Feb 17 '26 06:02

Dennis Williamson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!