I am trying to write a script to allow for easy writing to a firebase database using the REST API. Here is the part of the script causing issues:
#!/bin/bash
echo "patient username:"
read USER
echo "name:"
read NAME
echo "birthday:"
read BDAY
echo "insurance provider:"
read INSPROV
echo "insurance number:"
read INSNUMB
echo "group number:"
read GRPNUMB
form0="'"
form10='{\n "'
form1=${form0}${form10}
form2='": {\n "'
form3='name": "'
form4='",\n "birthday": "'
form5='",\n "insurance provider": "'
form6='",\n "insurance number": "'
form7='",\n "group number": "'
form8='"\n }\n}'
form9="' "
link="'https://billify-51384-default-rtdb.firebaseio.com/userinfo.json'"
#adding strings together
send1=${form1}${USER}
send2=${form2}${form3}
send3=${send2}${NAME}
send4=${send3}${form4}
send5=${send4}${BDAY}
send6=${send5}${form5}
send7=${send6}${INSPROV}
send8=${send7}${form6}
send9=${send8}${INSNUMB}
send10=${send9}${form7}
send11=${send10}${GRPNUMB}
send12=${send11}${form8}
send13=${send1}${send12}
send14=${send13}${form9}
URL=${send14}${link}
printf "$URL" >> tempfile.txt
URLFX=$(<tempfile.txt)
echo
echo "PRINTING DATA---------------------------------"
printf "$URLFX"
echo
curl -X PUT -d $URLFX
rm tempfile.txt
Sorry for all of the string combining, bash is terrible at making it efficient! I put the JSON data into a text file then make the script read it to fix the newline issues (which it seems to do). When I run the script I get this output:
PRINTING DATA---------------------------------
'{
"testuser": {
"name": "Johnny Smith",
"birthday": "January 3, 1903",
"insurance provider": "CompanyName",
"insurance number": "101010",
"group number": "1010"
}
}' 'https://billify-51384-default-rtdb.firebaseio.com/userinfo.json'
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched brace in URL position 1:
{
^
It seems to be formatting everything correctly, as when I add the printed data to the cURL command manually, it works and the data is added. What is cURL's issue with the script? Thank you!