Read in passwords with bash

March 25, 2005
37 comments Linux

This has taken me some time to figure out because I couldn't find anything on Google. I think the problem was that I didn't know what to look for.

If you have a bash script that asks the user to enter their username and password you use the read function in sh. But when you read in the password you don't want it to show on the screen what you're writing. Someone could be leaning over your shoulder. Python has a similar standard library module called getpass which works like this:


>>> from getpass import getpass
>>> p = getpass("Password please: ")
Password please: 
>>> print "Your password is", len(p), "characters long"
Your password is 5 characters long

That's fine if you do this via Python; but I needed to do it in one of my bash scripts. Here's how to do it:


#!/bin/bash
read -p "Username: " uname
stty -echo
read -p "Password: " passw; echo
stty echo

Now, hopefully this will help other people who get stuck with the same problem.

Add links to a text (take III)

March 22, 2005
0 comments Python

I've now made some improvements to my little addhrefs script. If you don't know what this is, read Add links to a text (take II) and Add links to a text with URLs which explains what this does.

The latest changes are that you can now pass your own function for turning an email or a URL into a link. For example:


>>> from addhrefs import addhrefs
>>> def emailify(e):return '<a href="/sendemail?to=%s">%s</a>'%(e,e)
>>> print addhrefs("Hello foo@bar.com", emaillinkfunction=emailify)
Hello <a href="sendemail?to=foo@bar.com">foo@bar.com</a>

You can also do the same with URLs by filling the urllinkfunction parameter.

Download: addhrefs-0.6.tgz

UPDATE Bug fixed version: addhrefs-0.7.tgz

U.S. memory championship

March 20, 2005
0 comments Misc. links

A great article about memory on MSN. It's about the American memory championship but the article also contains lots of information about memory in general that I didn't know. Another interesting thing is that for once the Americans don't whip us Europeans. The Europeans are apparently superior to the americans. At this U.S. championship two Europeans participated unofficially. One from England and one from Austria.

"Though Amsuess and Cooke's scores weren't officially tabulated, it was clear that Cooke would have destroyed the American competition. In the random words event, he managed 150 words in five minutes, 50 more than the best American score."

The Austrian chap seemed to have suffered but it's understandable because of the language barrier. However, this amuses me:

"And in speed cards, his best event, he clocked an impressive 45 seconds—almost four times faster than the best American—but lost out on a heap of points because he reversed two out of the 52 cards. Not dejected all, he loosened his tie, left the building, and walked to a nearby pub, where he memorized a deck of cards for the waitress and got three free beers in return."

Apparently the World championships are going to be held here in London, England where I live in August. Got to find out where and how I can get tickets to at least come and look.

BTW, here's the official website

UPDATE Following a few links eventually made me end up on www.worldmemorychallenge.com where they have a lovely Flash memory challenge. It doesn't take long and it's fun. My score was 19205 but I'm sure I can improve on that if I try again.

Fork Art, up yours Uri Geller

March 17, 2005
0 comments Misc. links

Fork-Art.com To some this might remind them of crap sold by buskers in plazas side by side with people who want to caricature you and show off their ugly pencil paintings of Leonardo di Caprio. But I'm impressed. Just going through the website it's obvious that this fork bender has loads of imagination. I appreciate that.

In the process of noticing Fork-Art.com I also did a quick search for Uri Geller on Google. I accidently landed on his own website uri-geller.com on which I found a very peculiar article: Looking in Uri's Mouth

Apparently, the famous and serious magazine New Scientist did an article in 1974 on how Uri Geller does his telepathic scams. The go into detail explaining the electronics Uri must hide in his teeth. Is it a joke? Difficult to tell. Amusing at least.

By the way, here's a step-by-step explaination on how he did is worn-out spoon bending trick: Spoon-bending How Uri Geller really does it!

Adminspotting t-shirts

March 17, 2005
1 comment Misc. links

Adminspotting Do you remember the ending of the film Trainspotting? It starts "Choose life. Choose a job. Choose a career. Choose a family. Choose a fucking big television. ..."

Now someone has done the equivalent based on the job of a system administrator a.k.a. sysadmin. This one starts "Choose no life. Choose sysadminning. Choose no career. Choose no family. ..." And they've prepared this as a t-shirt and are trying to sell it.

It's dark, depressing even, but very funny. I'm not a sysadmin but I admire the people who are.

Best Hubbles Space Telescope Images

March 13, 2005
0 comments Misc. links

Best Hubbles Space Telescope Images Space.com has a lovely image gallery of pictures from the Hubbles space telescope. They've done it so that you can vote for every picture similar to HOT or NOT.

What amazes me so much about these pictures is how different they all are. Granted that the pictures of Jupiter is going to be different from pictures of a nebula but within their categories all pictures are very different and at the same time equally amazing.

Try not to waste too much time on click and reading every picture. I did.

Swedish holidays explained

March 10, 2005
2 comments Sweden

First of all; I don't know much about the special holidays we have in Sweden which is pretty poor. I've got a vague idea about most of them but not much more.

This website attempts well in listing all of them and provides one text in Swedish and one in English. Now, having this website I can not only fill up my own knowledge but hopefully I will now also be able to explain some of our weird traditions to English speaking people.

This also led me to find Kalender.se which is what you can guess: a calendar in Swedish style. Interestingly it has the Swedish name days on it. Great work!

All the Seinfeld quotes you can eat

March 8, 2005
0 comments Misc. links

I love the Seinfeld show, but still I've never got around to finding any good websites about it. On Seinfeld Quotes they've made a nice and comprehensive list of quotes. In the rush of things I couldn't find my favorite but now I've got the quotes site bookmarked so there is hope.

"The woman had an orgasm under false pretenses. That's sexual perjury!" - Jerry, in "The Mango"

Good usage of drop-downs

March 5, 2005
0 comments Web development

Many websites have drop-downs to assist navigation. Usually this only applies to big sites where sitemaps are necessary and where you want people to get to any part of the site from the home page in one click. Sadly I've never had the challenge to develop any web sites that are that big and diverse in content but there's a time for everything.

Anyway, the Lufthansa site manages to use drop-downs efficiently. This is accomplished with Javascripts, but sadly nothing works if you don't have Javascript disabled. When you roll your mouse over "Worldwide Sites" it shows a drop-down underneath with a looong list of options. It's good because drop-downs are usually very ugly but powerful as navigation tools.

Truncated! Read the rest by clicking the link below.