You are not logged in.

#1 2008-05-23 05:07:58

bludra84
Member
Registered: 2007-10-25
Posts: 20

Shell Scripting and Embedded Quotes

Man I have been kitting my head against the desk trying to get this script to work. I need to embed a variable in a curl command that I'm passing via a bash script, and I'm having all sorts of trouble.

Here is the whole code so far:

#listen on port 9600 and put input into file
nc -v -l -p 9600 > input

#Get ***** SessionID
SESSION=$(curl -i -k -X POST -H 'Accept: application/xml' -d 'accessid=*****' -d 'password=*****' https://www.*****.com \
| egrep '<sessionid>.*</sessionid>' | sed -e 's/^[ \t]*//' -e 's/<sessionid>//' -e 's/<\/sessionid>//')

#assign variables
ACTION=`awk '{print $1}' < input`
SECONDS=`awk '{print $2}' < input`
DATE=`awk '{print $3}' < input`
WAVE=`awk '{print $4}' < input`

if [ "$ACTION" == "recall" ]; then
POST=$(curl -H 'Accept: application/xml' -H 'Content-Type: multipart/form-data; boundary=anteater' -X GET -b \'_session_id=$SESSIONID\'  http://www.*****.com)
fi

Bash ends up executing this command:

curl -H 'Accept: application/xml' -H 'Content-Type: multipart/form-data; boundary=anteater' -X GET -b ''\''_session_id=64484c0c379529554757260d3806a9d8'\''' http://www.*****.com

Note the wierd "\" that surrounds the session_id statement.

Do any of you know what I am doing wrong? Thanks for the help.

Offline

#2 2008-05-23 12:16:58

Procyon
Member
Registered: 2008-05-07
Posts: 1,807

Re: Shell Scripting and Embedded Quotes

If

-b \'_session_id=$SESSIONID\'
 translates to 
-b ''\''_session_id=64...'\'''

have you tried simpler things like

-b "_session_id=$SESSIONID"
or since there don't seem to be odd characters in $SESSIONID
-b _session_id=$SESSIONID

If that last one works I think you were just adding an actual quote to the argument of -b.

Last edited by Procyon (2008-05-23 12:20:30)

Offline

Board footer

Powered by FluxBB