April 19, 2024

Unix Shells: The Power and the Gory

No, the title does not include a typographical error. I really DO mean “the power and the gory“. Gory as in “horrific”. So…yeah. This post is about the decided ambivalence of a basic decision about Unix architecture that has dogged me (and, it must be assumed), many others, my entire life. But first let’s define what we’re talking about. For this, I will rely on this site (and refer to the image):

The main concept that unites all versions of UNIX is the following four basics:

  • Kernel: The kernel is the heart of the operating system. It interacts with hardware and most of the tasks like memory management, tash scheduling and file management.

  • Shell: The shell is the utility that processes your requests. When you type in a command at your terminal, the shell interprets the command and calls the program that you want. The shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell are most famous shells which are available with most of the Unix variants.

  • Commands and Utilities: There are various command and utilities which you would use in your day to day activities. cp, mv, cat and grep etc. are few examples of commands and utilities. There are over 250 standard commands plus numerous others provided through 3rd party software. All the commands come along with various optional options.

    Files and Directories: All data in UNIX is organized into files. All files are organized into directories. These directories are organized into a tree-like structure called the filesystem.

Clearly the shell is essential, as it is what you interact with directly to get work done. And yet you have a plethora of choices. And therein lies both the power and the gory. Let me break it down for you:

The Power

Well, OK, I admit that I’m drawing blanks here. I don’t quite get why you would want a shell that has fewer features than some other shell. Really I don’t. So, why shouldn’t there be one definitive shell that has all the possible features you might want? I really don’t know. So if you do, please enlighten me in the comments section below. I would appreciate it. Really I would.

The Gory

I can’t remember exactly when I got my first Unix account, but it was likely in 1986, when I started at UC Berkeley for my library degree. I had completed a minor in Computer Science at Humboldt State University in 1985, but most of that work was in Pascal and FORTRAN on various operating systems such as Harris. By the time I first made the acquaintance of Unix, I was in the basement of a monstrous building on the UC Berkeley campus called Evans Hall. After logging in to my first Unix account, I discovered I couldn’t log out.

I got a message that was something like “Not in login shell.” I can remember to this day my dismay and confusion. What was a shell? Why couldn’t I log out? At the time you were charged for your login time, so my fear was getting charged for login time after I was long gone. Desperate to logout, eventually I kept trying and that (of course) did the trick. But back then it was all a mystery. To some degree, it still is. What is a shell and why do I need to choose? Why would I want one shell over another?

I started in c shell (csh), but over time migrated to bash. And of course, how one accomplishes certain things are just slightly different, but different enough to make you stumble and fall. Thank you, Unix. Is this really necessary?

So here is one comparison of shells and what they support:

Now I’m wondering if I shouldn’t switch to z shell (zsh) since it appears to support the most options of them all. But…why? Unix, how many ways can you be arcane?

Share
Roy Tennant About Roy Tennant

Roy Tennant is a Senior Program Officer for OCLC Research. He is the owner of the Web4Lib and XML4Lib electronic discussions, and the creator and editor of Current Cites, a current awareness newsletter published every month since 1990. His books include "Technology in Libraries: Essays in Honor of Anne Grodzins Lipow" (2008), "Managing the Digital Library" (2004), "XML in Libraries" (2002), "Practical HTML: A Self-Paced Tutorial" (1996), and "Crossing the Internet Threshold: An Instructional Handbook" (1993). Roy wrote a monthly column on digital libraries for Library Journal for a decade and has written numerous articles in other professional journals. In 2003, he received the American Library Association's LITA/Library Hi Tech Award for Excellence in Communication for Continuing Education. Follow him on Twitter @rtennant.

Comments

  1. I would recommend giving zsh a try, it’s the only way to find out if you like it or not. It is a bit of a jump from bash to zsh, but certainly a much smaller difference there than between csh/tcsh and bash. My favorite feature of zsh is it’s extended globbing capabilities (http://linuxshellaccount.blogspot.com/2008/07/fancy-globbing-with-zsh-on-linux-and.html).

    If you are looking to dive in to zsh, you should check out the ‘Oh My ZSH’ project (https://github.com/robbyrussell/oh-my-zsh), which is like a big christmas present full of fun things to do with zsh. There’s also a good (free) Railscast intro to zsh and ‘Oh My ZSH’ (http://railscasts.com/episodes/308-oh-my-zsh).

  2. Steven Schwengel says:

    Yep, the power various kinds of shells are cool, powerful and really tricky to learn in a unix or other *ix environments.

    At first the various levels of “user privileges” and shell functions (think a supper ugly form of an operating system of a very very basic Mac OS X, Linux or other operating system) seemed to me to be overly complex and questionably useful. Yep it is ideal for that super hero doing cool things or boring routine producer (check mail, get mail, put mail in readable format, repeat ever 7 minutes until interrupted).

    If your on a Mac computer, that little built in app to get a taste of a shell is called “terminal”. It is your fastest way to get your feet wet or taste the power of a shell like the old DOS command prompt in Windows XP (which the above commands don’t work exactly the same way). Terminal can be pretty powerful, but the “cool” factor, if you want to ‘trick’ your’s out changing the color of the background, text and other text things like (underline are about it’s outer and practical limits of putting lipstick on a pig… It is not pretty but bacon tastes great.

    There so many things you can do in a shell, but not of all of it is practical or really useful for most users. Sure you can set a “cron” or chronology job, an automated alarm clock to carry out a function like check mail every 7 minutes Monday to Friday, but not on weekends in a box or Linux computer running a shell. But in reality how often do you need something done on a routine basis on your computer of choice automatically with this granularity? Or say setup an every third Thursday of the month back-up of every file on your computer in the a documents folder and save to a USB stick hanging off a usb port on your computer. Mmm, that is kind of useful…

    When messing around in a shell, it is probably a good idea not to be on an account with “root” or to high of “admin” user privileges if you just want to edit files or create power to do certain limited functions. The trick is certain users have functions or privileges or “fake root” power or “sudo” to do some things that can mess over your system greatly, and the opposite that a root user at times can’t do the boring stuff either. Generally it is a safeguard against doing dumb or inadvertent accidental stuff to the network or computer:)

    Also, one more key to shell. The privilege of creation, reading, writing or executing, or even completely re-writing a file or files are something only a geek could love with something that looks like scientific notation for file types in a few forms. If you thought file permissions is awkward for a PC or Mac, a shell file permissions structure is complicated because it defines permissions for you as the users, folks on a network, or folks even without network privileges when on the web as to read, write or no privileges at all.

    There are some cool things you can learn with a shell on a Linux box, like bash scripts, and other odds and ends. It is something that you might want to start small in… Chances are if you have got a website or a mac you have access to a unix shell.

    Thanks for the post. I had fun thinking shells and the unix command skill sets.