Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6661399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:16:29+00:00 2026-05-26T02:16:29+00:00

Some research revealed a few useful stackexchange posts, namely expanding variable in CURL ,

  • 0

Some research revealed a few useful stackexchange posts, namely expanding variable in CURL, but that given answer doesn’t seem to properly handle bash variables that have spaces in them.

I am setting a variable to the output of awk, parsing a string for a substring (actually truncating to 150 characters). The string I am attempting to POST via curl has spaces in it.

When I use the following curl arguments, the POST variable Body is set to the part of the string before the first space.

curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/GUID/SMS/Messages.xml' -d 'From=DIDfrom' -d 'To=DIDto' -d 'Body="'$smsbody'" -u SECGUID

smsbody is set as:

smsbody="$(echo $HOSTNAME$ $SERVICEDESC$ in $SERVICESTATE$\: $SERVICEOUTPUT$ | awk '{print substr($0,0,150)}')"

So the only portion of smsbody that is POSTed is $HOSTNAME$ (which happens to be a string without any space characters).

What is the curl syntax I should use to nest the bash variable properly to expand, but be taken as a single data field?

Seems pretty trivial, but I messed with quotes for a while without luck. I figure someone with better CLI-fu can handle it in a second.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:16:30+00:00Added an answer on May 26, 2026 at 2:16 am

    It looks like you have an extra single quote before Body. You also need double quotes or the $smsbody won’t be evaluated.

    Try this:

    curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/GUID/SMS/Messages.xml' \
        -d 'From=DIDfrom' -d 'To=DIDto' -d "Body=$smsbody" -u SECGUID
    

    If the $s are still an issue (I don’t think spaces are), try this to prepend a \ to them:

    smsbody2=`echo $smsbody | sed 's/\\$/\\\\$/g'`
    curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/GUID/SMS/Messages.xml' \
        -d 'From=DIDfrom' -d 'To=DIDto' -d "Body=$smsbody2" -u SECGUID
    

    If I run nc -l 5000 and change the twilio address to localhost:5000, I see the smsbody variable coming in properly.

    matt@goliath:~$ nc -l 5000POST / HTTP/1.1
    Authorization: Basic U0VDR1VJRDphc2Q=
    User-Agent: curl/7.21.6 (x86_64-apple-darwin10.7.0) libcurl/7.21.6 OpenSSL/1.0.0e zlib/1.2.5 libidn/1.20
    Host: localhost:5000
    Accept: */*
    Content-Length: 45
    Content-Type: application/x-www-form-urlencoded
    
    From=DIDfrom&To=DIDto&Body=goliath$ $ in $: 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made some research on Stackoverflow about reverse for loops in C++ that
After some research, it is my understanding that this is not possible. I can
after I did some research on the subject, I found that Windows Live stopped
After doing some research, it would seem that errno 150 occurs when either table
I'm doing some research in how to implement a event-handling scheme in C++ that
after some research I found that the best option for my current proyect is
I have done some research and still confused, This is my outcome of that
I'm doing some research on software cost estimation models and methods with a few
I have been doing some research about this and have found a few similar
I'm doing a some research on the feasiblity of a Sharepoint project that has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.