user7988893
user7988893

Reputation:

How to joint the string in bash?

sql="UPDATE wp_posts SET post_content = replace(post_content, 'domain','http://123.456.789.1/wp');"
echo $sql
UPDATE wp_posts SET post_content = replace(post_content, 'domain','http://123.456.789.1/wp');

The sql string is what i want.
Assign the ip address to a variable.

$ip="123.456.789.1"
sql="UPDATE wp_posts SET post_content = replace(post_content, 'domain',"http://${ip}/wp");"
echo $sql
UPDATE wp_posts SET post_content = replace(post_content, 'domain',http://123.456.789.7' /wp);

I can't get the sql string when ip address is a variable.
How to fix it?

Upvotes: 0

Views: 152

Answers (1)

dmadic
dmadic

Reputation: 477

Variable names should not start with $. So call the variable ip instead of $ip.

Since your sql string is declared with double quotes, you don't need another double quotes inside "http://${ip}/wp".

This should do the work:

ip="123.456.789.1"
sql="UPDATE wp_posts SET post_content = replace(post_content, 'domain','http://$ip/wp');"
echo "$sql"

Output:

UPDATE wp_posts SET post_content = replace(post_content, 'domain','http://123.456.789.1/wp');

Upvotes: 1

Related Questions