[Chapter 9] Saving Time on the Command Line
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:34:51Z

#

| Chapter 9 |

# 9. Saving Time on the Command Line

Contents:
What's Special About the UNIX Command Line
Fix a Line Faster with Line-Kill and Word-Erase
Reprinting Your Command Line with CTRL-r
Use Wildcards to Create Files?
Build Strings with { }
String Editing (Colon) Operators
String Editing in ksh and bash
Filename Completion: Faster Filename Typing
Don't Match Useless Files in Filename Completion
Filename Completion Isn't Always the Answer
Repeating a Command with a foreach Loop
The Bourne Shell for Loop
Multiline Commands, Secondary Prompts
Using Here Documents for Form Letters, etc.
Throwaway Scripts for Complicated Commands
Command Substitution
Handling Lots of Text with Temporary Files
Process Substitution
For the Impatient: Type-Ahead
Too Many Files for the Command Line
Handle Too-Long Command Lines with xargs
xargs: Problems with Spaces and Newlines
Workaround for "Arguments too long" Error
Get File List by Editing Output of ls -l, grep, etc.
The C Shell repeat Command
Expect

## 9.1 What's Special About the UNIX Command Line

One of UNIX's best features is the shell's command line. Why? Every modern operating system has a command line; we don't use card readers with obscure job setup cards any more. What makes UNIX's special?

The UNIX shell command line allows lots of shortcuts. Some of these you'll find in other operating systems; some you won't. In this chapter, we'll introduce a lot of these shortcuts. Among other things, we'll discuss:

- Faster erasing (9.2) of mistakes with the line-kill and word-erase characters. (These aren't just a feature of the shell; they work at many places other than a shell prompt.)

- Filename completion (9.8, 9.9, 9.10), which allows you to type the beginning of a filename and let the shell fill in the rest.

- Command substitution (9.16), which lets you use the output from one command as arguments to another. (Note: this is different from pipelining (1.4).)

- Process substitution (9.18) in bash, and a script named ! for other shells, lets you put the output of a command into a temporary file - and give that filename to a process.

- Type-ahead (9.19), the ability to type your next command (or commands) while the previous command is still running.

- How to handle command lines that become too long (9.20, 9.21, 9.23).

Some fundamental command-line features that we aren't discussing in this chapter, but which are discussed elsewhere, are:

- Job control (12.1), which lets you run several commands at the same time.

- Aliases (10.2), or abbreviations, for commands. Shell functions (10.9) are similar.

- Command-line editing (11.13) and history substitution (11.1) are two different ways (both useful) to "recall" previous commands.

- Quoting (8.14, 8.15), the way you "protect" special characters from the UNIX shell.

- Wildcards (15.2).

You don't need to be a command-line virtuoso to use UNIX effectively. But you'd be surprised at how much you can do with a few tricks. If all you can do at the command line is type `ls` or start FrameMaker, you're missing out on a lot.

- ML

8.20 How Many Backslashes? |  | 9.2 Fix a Line Faster with Line-Kill and Word-Erase