Zach Margolis


Nifty Tip: Twitter from your command line

Saturday March 15th, 2008

So I saw a neat tip from and saved it to my My friend blogged about that, reposting the tip. He noted that it could be used with an alias. After a bit of research, I've made a shell script and think it's time to share with the world.

Also, I just checked his blog again, and he has another way to do the exact same thing I'm about to describe. So firstly, we're going to pair an alias with a shell script. The alias is what you call at any time, and the shell is what does the legwork, however minimal that is.

The shell script is based off of the code from Wired curl -u username:password -d status="$1" -k The $1 in the middle takes an argument from whatever calls it, which in this case is going to be the alias. The next step is to save this file as a .sh in a location you remember. Mine's in /Documents/Misc/Code/

So now make an alias. From your Unix/Linux terminal, call alias twitter='sh ~/Documents/Misc/Code/' and basically everything after the ~ is your path. This is only a temporary alias, that disappears as soon as you logout (or close the terminal window).

So what about permanent aliases? I didn't know the difference until recently, but after a bit of research, I found something that works for me. I created a file in my home directory called .profile. In other places, this may be called .bashrc or .cshrc but mine was .profile (if you already have one of these, just append this next line). alias twitter="sh ~/Documents/Misc/Code/" Notice the double quotes, too. You're also going to have to logout and login, or make a new shell window to test this. Use the alias command to print a list of aliases to confirm that this shortcut works.

Now for the fun part! Just type twitter your twitter message here to Twitter away!

Tags: projects


How would you do this without saving your password in the file? Perhaps put it in /root/.twitter
Kut on May 1st at 2:22 PM

Leave a Comment

Captcha. Click for audio equivalent Refresh Captcha
Allowable HTML tags are <a>, <p> and <br>


Categorized Posts
View the distribution of all tags.


Complete Archives
View a list with all of the blog entries.