I have a python code that will send a HTTP request to a webserver to update its time according to PC time and this code works fine:
current_time = str(time.time())
url = "http://192.168.1.1/cgi-bin/Operation.cgi?data={\"action\":\"synctime\",\"newtime\":" + current_time + "}"
response = urllib.request.urlopen(url)
Then I'm trying to translate this code into a bash script to do the same thing and this is what I have:
current_time=$(date +%s)
url="http://192.168.1.1/cgi-bin/Operation.cgi?data={\"action\":\"synctime\",\"newtime\":$current_time}"
response=$(curl -s "$url")
I'm echoing result from the URL variable and it looks like this:
}ttp://192.168.1.1/cgi-bin/Operation.cgi?data={"action":"synctime","newtime":1681742302
There's a closing curly braces in the beginning of this string replacing the "h" letter and I don't understand why the output being like this. I tried to change the format to use single quotes and also concatenate the current_time variable in url variable but nothing seems to work.
Can someone please explain why this curly braces is where it is and what can I do to fix it?