Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl ignore --data starting with @ sign: don't read from file

In slack you can script slackbot to post messages to a channel like this:

curl --data "$msg" $'https://<yourteam>.slack.com/services/hooks/slackbot?token=<yourtoken>&channel=#random'

Now i'd like to mention a username as the first part of the message like msg="@joernhees hello self".

The problem with this is that if the --data argument of curl starts with an @ sign it will interpret the string after the @ as filename and post its content. Is there a way to make curl ignore the @ sign and to send a literal @ as the first char of a post request?

like image 871
Jörn Hees Avatar asked Nov 19 '25 22:11

Jörn Hees


1 Answers

If you are on a new version of cURL you can also use the --data-raw option:

http://curl.haxx.se/docs/manpage.html#--data-raw

A word of warning is that looking my laptop it appears Yosemite ships with an older version of cURL.

In general if you're creating tools to post to Slack I'd recommend using an HTTP library in your script rather than calling out to a shell and invoking the curl command.

like image 53
Ben Avatar answered Nov 22 '25 14:11

Ben