Here is my simple script
#!/bin/sh
thefile=/home/ark/arkserver/ShooterGame/Saved/SaveIsland/1288804998.arktribe
while inotifywait "${thefile}" ; do
a=\"`strings ${thefile} | tail -n 5 | head -n 1 | sed 's/<[^>]*>//g'`\"
echo $a
curl -H "Content-Type: application/json" -X POST -d '{\"username\": \"Island\", \"content\": $a}' https://discordapp.com/api/webhooks/5738674701/OjRQiAWHq5mX0Tn2MfBlF-mI41TWrVYVAbOfXpeZWqo8
done
Here is the output
Setting up watches.
Watches established.
/home/ark/arkserver/ShooterGame/Saved/SaveIsland/1288804998.arktribe ATTRIB
"Day 600, 21:31:17: Phorce1 demolished a 'Campfire'!"
{"code": 50006, "message": "Cannot send an empty message"}Setting up watches.
Watches established.
I cannot figure out how to get the curl command properly quoted with the variable inserted in the middle. This is what the command should look like. This works when typed out on the command line
curl -H "Content-Type: application/json" -X POST -d '{"username": "test", "content": "Day 600, 14:51:00: Phorce1 demolished a 'Campfire'!"}' https://discordapp.com/api/webhooks/594723628738674701/OjRQn2MfBlF-FJVl1cWwMlD6UQf0c
I have tried many different forms of quoting. The fact that it echos $a as properly quoted but still breaks something in the command that uses it confuses me.
(Yes, I mangled my webhook address)
This question was marked as a duplicate to another question, but the answers to that question were to simply escape the quotes. The "nested quotes" nature of the curl command line in my script causes those answers to fail. I tried many forms of escaping the quotes before posting my own question. Using escaped quotes as mentioned in the answer on the other question I could get a simple "echo" of the variable inside quotes with no problem but inserting that "inside the quotes that were inside other quotes that were inside another set of quotes" in the curl command line would fail.