Thursday, October 18, 2012

The Pioneers of UNIX

Steve Jobs? Steve Jobs didn't do jack. If you want to know who is responsible for the modern world you have to look at the people working at Bell Labs in the 1970s and 1980s. The people who created UNIX. It was from that invention that we have the modern world. UNIX led to Linux which led to Android. UNIX led to the BSD family of operating systems which led to Apple OSX. UNIX led to the C programming language in which most system-level software today is written. Ever wonder why URLs use forward slashes? It's because UNIX was instrumental in the creation of the Internet.

Below is a 27 minute promotional video produced in 1982 by Bell Labs, where we meet some of the giants on whose shoulders we all stand today. Included in the video are:

In addition, you'll get a good look at some computer hardware from the early 1980s which is around the time I was starting my transition from TRS-80s to IBM PCs.

Sunday, October 14, 2012

new_script Version 3

The most popular script on the old version of was new_script, a bash shell script that created bash shell scripts. That is, a script template generator. A few months ago I rewrote new_script to modernize it and make better use of bash features, including arrays. The new version is less than half the length of the previous version and yet it does more.

Using new_script will save you a lot of work by creating a customized template incorporating a parser for your script's command-line options and arguments. The template also includes a number of useful housekeeping routines such as error and signal handlers. The generated script is fully functional (though it does nothing) and is ready for you to insert your program-specific logic.


new_script [-h|--help] [-q|--quiet] [-s|--root] [script]


new_script will, by default, prompt the user for details about the script to be generated:

Enter script output filename >

Choose a name for the generated script file.

Enter purpose of script >

Enter a one-line description of the script.

Include GPL license header [y/n]? >

Entering "y" will insert a GPL license header into the comment block at the beginning of the script.

Does this script require superuser privileges [y/n]? >

Entering "y" will insert a routine that verifies the user has superuser privileges before allowing the script to execute.

Does this script support command-line options [y/n]? >

If you intend to support command-line options for your script, answer "y".

Option 1:
Enter option letter [a-z] (Enter to end) >

If command line options are desired, a series of prompts will appear. First, you will be asked for the short (single letter) form of the option. Enter a letter in the range of a-z to define the option or enter nothing to end the option input loop.

Description of option ------------------->

Enter a short description of the option. This will be used in the "help" message.

Enter long alternate name (optional) ---->

Enter a single-word long option name if desired. For example, if you have an option "h" for a help function, you can specify an alternate long form name for the option such as "help." When your script is executed, you can invoke the help function by including either -h or --help on the command-line.

Note that new_script always includes the "h" and "help" options automatically by default.

Enter option argument (if any) ---------->

If your option requires an argument, enter a single-word descriptor here. For example, if you were creating a script named my_script supporting both an input and an output file, you might have an option for each with their corresponding arguments such as:

my_script -i infile -o outfile

After you finish entering your option information, new_script will generate your custom script template.

Your script will contain a handy error handling routine called error_exit, which is used like this:

error_exit error_message

where error_message is a string containing a descriptive error message. The error_exit function outputs the error_message string to standard error, calls the clean_up function to perform any necessary housekeeping, then exits with an exit status of 1. Here is an example:

error_exit "Something bad happened!"

You can see other examples within the new_script code itself.


The new_script program supports the following command-line options:

-h, --help
Display a help message and exit.

-q, --quiet
Quiet mode. Do not prompt user for script information and output default script to standard output.

-s, --root
Require superuser privileges for execution of generated script.

You may also include the desired file name for the generated script on the command-line after any specified options.


You can find the script here. To install it, just highlight the text and copy it into a text editor and save the resulting file. If you're feeling clever, you can directly write it to a file via the command-line. Highlight the text as before, open a terminal and enter the following command (assuming you have a bin directory in your home directory, otherwise adjust as needed):

cat > ~/bin/new_script

Paste the script into the terminal by clicking the middle mouse button and type Ctrl-d.

Once you have written the script, give it execute permissions like so:

chmod +x ~/bin/new_script 

Thursday, October 4, 2012

My Raspberry Pi Adventure

Last Christmas, my friend +Norman Robinson gave me a BeagleBoard-xM computer to play with. The BeagleBoard is a small, single-board, ARM-based computer. As I started to work with it I was impressed with its relative performance and low-power consumption. However, due to its price (approx. $150), I didn't think it represented a tremendous value. After all, I only paid $199 for my HP Mini netbook at my local computer store and the netbook comes with a case and a keyboard!

I had been hearing a lot about the Raspberry Pi computer which appeared to be very similar to the BeagleBoard but only costs $35. That price, being clearly in impulse-buy territory, appealed to my computer buying impulses.

First Discovery: They're hard to get.

The Raspberry Pi computer is the brainchild of a group of British computer science educators. They set out to solve a problem:
The idea behind a tiny and cheap computer for kids came in 2006, when Eben Upton and his colleagues at the University of Cambridge’s Computer Laboratory, including Rob Mullins, Jack Lang and Alan Mycroft, became concerned about the year-on-year decline in the numbers and skills levels of the A Level students applying to read Computer Science in each academic year. From a situation in the 1990s where most of the kids applying were coming to interview as experienced hobbyist programmers, the landscape in the 2000s was very different; a typical applicant might only have done a little web design. 
Something had changed the way kids were interacting with computers. A number of problems were identified: the colonisation of the ICT curriculum with lessons on using Word and Excel, or writing webpages; the end of the dot-com boom; and the rise of the home PC and games console to replace the Amigas, BBC Micros, Spectrum ZX and Commodore 64 machines that people of an earlier generation learned to program on.
As they had modest objectives and resources, they only planned to produce a few thousand boards, however when they announced the computer and its price, they were flooded with hundreds of thousands of orders. Needless to say, this has led to some supply problems. It was many months before the boards became generally available in the U.S.. Even now, you should expect a long wait to receive a board.

I ordered mine from Allied Electronics and waited about 12 weeks for delivery.

If you're willing to pay more, there are scalpers out there (like this guy on Amazon) who will happily sell you a board albeit at a greatly inflated price.

Second Discovery: You'll need accessories.

For $35 all you get is a bare board, nothing else, not even documentation. That's available on-line. I ordered a case, power supply, and cables from Adafruit Industries which offers an extensive array of Raspberry Pi accessories. You'll also need a 4GB (or larger) SD card to act as its boot disk.

One interesting cable I bought from Adafruit was the USB TTL to Serial Cable. With this cable, you can both power the Raspberry Pi and interact with it via a serial terminal program on your computer. I installed GtkTerm on my Ubuntu box and was able to work with the board while I waited for my back-ordered power supply.

The Raspberry Pi is powered with 5 volts over a USB cable so many mobile phone chargers will work. My Nexus 7 charger worked fine for testing purposes.

Third Discovery: It ain't no slouch.

So how good is a $35 computer? Surprisingly good. In terms of computing horsepower, you can think of the Raspberry Pi as a late 1990s-era desktop PC, but with a better graphics card. The CPU performance is roughly equivalent to a 300 MHz Pentium II.

The board comes equipped with 256 MB of RAM, 2 USB ports, an Ethernet port, HDMI video out, RCA composite video out, and a speaker port. Notice that there is no VGA output. It's really designed to be hooked up to a digital TV or monitor via HDMI. If you have a monitor that supports DVI (as I do), you can use a HDMI-to-DVI cable. I only used a monitor with the board once and it worked fine. Be aware that the HDMI is not bi-directional, meaning that the board cannot detect the capabilities of the monitor it's attached to. You may need to adjust some configuration files to get the video the correct size on your monitor. Another limitation of the Raspberry Pi is that it does not have a real-time clock. It relies on a network connection and Network Time Protocol to keep accurate time.

Fourth Discovery: USB is an issue.

Due to its limited power supply, both my BeagleBoard and Raspberry Pi cannot meet the official specification for USB power output. This means you should not try to power devices via USB. My mouse and keyboard worked okay, but forget about USB powered hard disks and the like. Either use an externally powered device or use a good quality powered USB hub.

Fifth Discovery: There's lots of software.

I set up my Raspberry Pi as a headless media server. I downloaded and installed Raspbian, the version of Debian 7 for the Raspberry Pi. It is officially supported by the Raspberry Pi Foundation and you can download it from their site. To install the image, use dd to write the image file on to the SD card. After it's done, insert the SD card into the Raspberry Pi, attach a monitor and keyboard, plug in the power supply and it boots up. There are a few setup questions (start with setting the correct keyboard layout for your locale) and you're done.

Most every application that's available for Debian (more than 30,000) is also available for the Raspberry Pi. I installed Samba (Windows style file server), Apache (web server), OpenSSH-server (secure shell server), byobu (terminal screen multiplexer), apcupsd (UPS monitor), and the Logitech Media Server.

It is also possible to build an all-text Linux workstation as I describe in my blog series.

I attached a 200 GB 3.5 inch external hard drive and added a line to /etc/fstab to explicitly mount it since Raspian, in its standard form, does not automatically mount drives.  

I wrote a bash shell function for my .bashrc file (on the Raspberry Pi) to provide a quick snapshot of the system's health:

status() {
        { echo -e "\nuptime:"
        echo -e "\ndisk:"
        df -h 2> /dev/null
echo -e "\nblock devices:"
        echo -e "\nmemory:"
        free -m
        echo -e "\nrsync_backup.log:"
        tail /var/log/rsync_backup.log
        echo -e "\nsyslog:"
        tail /var/log/syslog
        } | less

The rsync_backup.log file is created by a script of mine that performs nightly backups of the system.

Here is my Raspberry Pi in its final production configuration:

On the left we see the power cable, on the right, USB cables to the APC UPS and external hard drive, and 10 Base-T Ethernet.

Final Discovery: I like it.

The Raspberry Pi, along with my BeagleBoard, have replaced two old desktop machines that acted as servers on my home network. My office is now eerily quiet (and much cooler!).

Thursday, September 27, 2012

Unity Tutorial Video

I came across this 27-minute Unity tutorial a few weeks back. If you you are using Ubuntu 12.04, or are considering it, check it out. It is pretty through and explains many of its hidden features.

Unity remains controversial and I have mixed feelings about it myself. I think that application discovery is more difficult when using the dash than it is using the previous pull-down menu system. Changing workspaces requires an additional step in Unity and the placement of window controls and menus in the top corner of the workspace is awkward at best.

But on the other hand, I get what the designers are trying to do. In addition to making the user interface more touch-friendly (because it's the future du jour), it attempts to reduce distraction on the desktop and make your work easier to focus on.

I have 12.04 running on my laptops and netbooks (it's a good fit for netbooks) and will be upgrading my main desktop to it soon.

Tuesday, May 8, 2012

Announcing Version 3

Over the weekend I went live with a major revision to the site. This update modernizes and improves the tutorials and simplifies the site to bring its content into sharper focus.

Both the Learning The Shell and Writing Shell Scripts tutorials have been updated and now incorporate some material from the book. The order of the lessons has also been slightly revised.

A few features of the old version of the site, such as the SuperMan Pages, Script Library, mailing lists, and RSS feed have been deprecated. If you have links to the old features, they will still work but they may go away in the future. I intend to add more links to external references (i.e. Further Reading sections to the lessons) and a few scripts to the new Resources page.

Please look it over and let me know about typos, and other screw-ups I may have missed. Thanks.

Next up: I am beginning work on the second edition of the book. If all goes well, you can expect to see that in the late summer.

Wednesday, April 4, 2012

How Linux Is Made

The Linux Foundation has released a short video that explains (in very high-level terms) the Linux kernel development process. It goes on to tout Linux as the dominating platform for smart phones, supercomputers, web commerce, and enterprise infrastructure.

Wednesday, January 11, 2012

Announcing The Linux Command Line from No Starch Press

Starting today, the printed version of The Linux Command Line will be published by No Starch Press. It is available now wherever fine books are sold, including Amazon and Barnes & Noble.

In October of 2010 I received an email from an editor at No Starch saying that they were impressed with my book and asked if I would be interested in commercially publishing it. This started a long negotiation with them over rights. I wasn't interested in a commercial version per se, rather I was interested in having greater reach. I know that readers outside the United States have difficulty purchasing the printed version from, and that I am unable to provide ePub and other e-reader formats. My publishing agreement with No Starch Press grants them exclusive rights to produce the printed version and all electronic versions except PDF and HTML. Those formats will remain mine. What's important here is that the freely distributable PDF will continue to be available, and I will continue to develop it. I plan to start work on the second edition this spring.  I'm also planning to rewrite the tutorials based on the contents of the book which is, frankly, much more accurate and up-to-date.

So how is the No Starch Press version different from my version? It's about 99% the same. The chapter numbering is different, it's been copy edited to further improve my so-called English, and it's been reformatted to fit their typographical style. But in terms of content, it's virtually the same as the freely distributable version.

To celebrate the introduction of The Linux Command Line, No Starch Press is offering a limited time promotion when you buy the book directly from the No Starch website. Use the discount code GREPITGOOD to get 40% off The Linux Command Line. One week only! Free ebook with all print book purchases.

Further Reading