'Bash variable not working in http request/response body

#!/bin/bash

object=$1
tenant=$2

server=$(sshpass -p 'password' ssh -tt root@ipaddress "/opt/something/sh/mysql -A 'admin_site' -e 'select id from something_servers where tenantcode=$2' | grep -o '[0-9]*'")

http -b "http://ipaddress/?app=something&t=users&v=users&server=$server&apikey=apikey&action=something.$1.list"

Everything seems to work fine. The value of variable $server is "24" as it should be. But still, when I call upon it in the http request it simply won't work... I honestly have no clue. I tested the variable's value by echoing it and it's correct. But for some reason when using it in the request it doesn't.

Any ideas?



Solution 1:[1]

Your code creates a variable called object and you set its value to the value stored in a variable called 1.

It creates a variable called tenant and sets it to the value of what's stored in the variable called 2.

It then creates a variable called server and then calls a subshell and runs the routine between $().

In the subroutine:

You use single quotes around

-e 'select id from something_servers where tenantcode=$2'

But for variable interpolation to work, you would need to use double quotes

Maybe that is your issue?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jared DiScipio