CHAPTER 17 Cool Shell Tricks
CHAPTER 17 Cool Shell Tricks The BASH shell is the product of many years of development work by a lot of people. It comes from the old days of Unix and was an important step in computer software evolution. It s a program that retains complete simplicity, yet packs in more features than most users could ever hope to use. One of the best things about the shell is its sheer power. If you ever wonder if you can do a task differently (and more efficiently), you ll probably find that one of the many BASH developers has implemented a method to do so. Once you learn these techniques, you ll find you can whiz around the shell at blinding speed. It s just a matter of exploring the far reaches of the shell, and that s what you ll do in this chapter. Hold onto your hats, because it s an exciting ride! Using Autocompletion The Tab key is your best friend when using the shell, because it will cause BASH to automatically complete whatever you type. For example, if you want to run Ubuntu s web browser, you can enter firefox at the command line. However, to save yourself some time, you can type fir, and then press Tab. You ll then find that BASH fills in the rest for you. It does this by caching the names of the programs you might run according to the directories listed in your $PATH variable (see Chapter 13). Of course, autocompletion has some limitations. On my Ubuntu test system, typing loc didn t autocomplete locate. Instead, it caused BASH to beep. This is because on a default Ubuntu installation, there is more than one possible match. Pressing Tab again shows those matches. Depending on how much you type (how much of an initial clue you give BASH), you might find there are many possible matches. In this case, the experienced BASH user simply types another letter, which will be enough to distinguish the almost-typed word from the rest, and presses Tab again. With any luck, this should be enough for BASH to fill in the rest.