Total noob in BASH. Trying to learn. I have the following bash script to make an API request:
#!/bin/bash
if [ $1 = "new_event" ]; then
a='https://www.googleapis.com/calendar/v3/calendars/'
b=$2
c='/events?access_token='
d=$3
path=$a$b$c$d
echo $4
OUTPUT="$(curl -s -H "Content-Type: application/json" $path -d $4 )"
echo "${OUTPUT}"
fi
Positional arguments are 'new_event', calendarId, access token and json string. If I run the script I get:
first echo is the json string I pass as parameter in the call:
' {"guestsCanSeeOtherGuests": false, "location": "", "description": "TEST", "reminders": {"useDefault": false}, "start": {"dateTime": "2017-07-06T14:00:00", "timeZone": "America/Sao_Paulo"}, "end": {"dateTime": "2017-07-06T15:00:00", "timeZone": "America/Sao_Paulo"}, "guestsCanInviteOthers": false, "summary": "TEST", "status": "tentative", "attendees": []} 'second echo gives me parsing error.
BUT, if I copy the echoed json string and replace $4 for it, everything works.
OUTPUT="$(curl -s -H "Content-Type: application/json" $path -d ' {"guestsCanSeeOtherGuests": false, "location": "", "description": "TEST", "reminders": {"useDefault": false}, "start": {"dateTime": "2017-07-06T14:00:00", "timeZone": "America/Sao_Paulo"}, "end": {"dateTime": "2017-07-06T15:00:00", "timeZone": "America/Sao_Paulo"}, "guestsCanInviteOthers": false, "summary": "TEST", "status": "tentative", "attendees": []} ' )"
Any hint why is it not working with the positional argument while it works if I paste it's content?
Thanks!
$4? It seems non-existent from the looks of it ...