tags:

views:

238

answers:

3

Hi, I'm looking to update twitter using cURL. I've written a bash fuction, but I'm not sure how to get it to accept a line as an argument to use as status text. The current function just accepts the first word as an argument. Also, can I prevent it from returning the XML file or suppress it from going to stdout?

Thanks

#!/bin/bash
function tweet {
  curl -s -u username:password -d status="$1" http://twitter.com/statuses/update.xml
}

PS - I know there are other questions re: cURL and Twitter on SO but none answer my question.

+1  A: 

Random guess: When typing the command in bash, have you tried putting the first command line arg in "" so it groups the whole post into $1? That works in some shells.

msp
That worked for the argument alright, thanks, would prefer not to need to though. Any idea how to suppress the returned output? Maybe I need to write a more detailed function
Griffo
+2  A: 

Yes, and yes. In bash, you want to use $* instead of $1. To suppress anything from going to stdout, just redirect it to /dev/null. So, your code would look like:

#!/bin/bash
function tweet {
  curl -u username:password -d status="$*" http://twitter.com/statuses/update.xml > /dev/null
}
Joe
Beautiful, thanks!
Griffo
@Joe Actually, using the -s switch with cURL makes it silent and so it also hides the progress meter
Griffo
You can do `curl -o /dev/null -s ...` also.
Dennis Williamson
A: 

Maybe you just need to create a variable and publish it on twitter. I published my current ip via the following code: http://www.commandlinefu.com/commands/view/3909/tweet-my-ip-see-your-machine-ip-on-twitter-

m33600