The Shell Command Line

Having a basic understanding of the capabilities of the shell command line can help you write better shell scripts. If, once you have finished reading this short introduction, you want to learn more about the command line, check out Chapter 33, "Command Line Masterclass." You can use the shell command line to perform a number of different tasks, including

Searching files or directories with programs using pattern-matching, or expressions; these commands include the GNU gawk (linked as awk) and the grep family of commands, including egrep and fgrep.

Getting data from and sending data to a file or command, known as input and output redirection.

• Feeding or filtering a program's output to another command (called using pipes).

A shell can also have built-in job-control commands to launch the command line as a background process, suspend a running program, selectively retrieve or kill running or suspended programs, and perform other types of process control.

Multiple commands can be run on a single command line using a semicolon to separate commands:

6:02pm up 4 days, 24 min, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM [email protected] IDLE JCPU PCPU WHAT

bball pts/0 1:14pm 0.00s 0.57s 0.01s w total used

Mem: 190684

Swap: 1277156


/dev/hdal none free 184420 23980 2516 1k-blocks 11788296 95340


cached 17620


6264 166704 1274640

Used Available Use% Mounted on 4478228 6711248 41% /


This example displays the output of the w, free, and df commands. Long shell command lines can be extended inside shell scripts or at the command line by using the backslash character (\). For example,

> command line and"" ; echo ""shows that multiple commands \

this is a long command line and shows that multiple commands may be strung out.

The first three lines of this example are a single command line. In that single line are two instances of the echo command. Note that when you use the backslash as a line-continuation character, it must be the last character on the command line (or in your shell script, as you will see later on in this chapter).

Using the basic features of the shell command line is easy, but mastering use of all features can be difficult. Entire books have been devoted to using shells, writing shell scripts, and using pattern-matching expressions. The following sections provide an overview of some features of the shell command line relating to writing scripts.

Was this article helpful?

0 0

Post a comment