导出 MySQLIP="2.2.2.2"
consul kv put micro/mysql '{"enabled": true, "url":"root:yourpassword@($MySQLIP:3306)"}'
上面的命令运行时如何让$MySQLIP变成2.2.2.2?我知道这与 shell 脚本有关。请帮忙。
导出 MySQLIP="2.2.2.2"
consul kv put micro/mysql '{"enabled": true, "url":"root:yourpassword@($MySQLIP:3306)"}'
上面的命令运行时如何让$MySQLIP变成2.2.2.2?我知道这与 shell 脚本有关。请帮忙。
Use double quotes to allow variables to be expanded:
consul kv put micro/mysql '{"enabled": true,
"url":"root:yourpassword@'"$MySQLIP"':3306"}'
Above, we are essentially concatenating three strings, the first and last are single-quoted, and the 2nd is double quoted. You can also write:
consul kv put micro/mysql "{\"enabled\": true,
\"url\":\"root:yourpassword@$MySQLIP:3306\"}"
if you find it clearer. There a many ways to quote strings in the shell.