Donation?

Harley Hahn
Home Page

Send a Message
to Harley


A Personal Note
from Harley Hahn

Unix Book
Home Page

SEARCH

List of Chapters

Table of Contents

List of Figures

Chapters...
   1   2   3
   4   5   6
   7   8   9
  10  11  12
  13  14  15
  16  17  18
  19  20  21
  22  23  24
  25  26

Glossary

Appendixes...
  A  B  C
  D  E  F
  G  H

Command
Summary...

• Alphabetical
• By category

Unix-Linux
Timeline

Internet
Resources

Errors and
Corrections

Endorsements


INSTRUCTOR
AND STUDENT
MATERIAL...

Home Page
& Overview

Exercises
& Answers

The Unix Model
Curriculum &
Course Outlines

PowerPoint Files
for Teachers

Exercises and Answers for Chapter 13...

Using the Shell: Commands and Customization

Review Question #1:

What is an alphanumeric character?

What is a metacharacter?

Name three metacharacters and explain what they are used for.

Answer

An alphanumeric character is any character that is either a letter (alpha) or a number (numeric). Punctuation and special characters are not considered to be alphanumeric.

A metacharacter is a character that has a special, non-literal meaning. Metacharacters are used within the shell for specific purposes.

For reference, the table below shows all the important metacharacters and how they are used. I have also listed the chapter in which I discussed each metacharacter.

There are so many metacharacters you shouldn't try memorize them all outright. All that will happen is that you will fry your gray matter and end up in a House for the Feeble-Minded(*). What makes more sense is to practice using each metacharacter, one at a time, as you learn about the service it provides.

* Footnote

Let me ask you a personal question.

Are you a smart, talented person with an inborn love for thinking, learning and creativity? Someone who, despite your native intelligence, often feels out of step because — unlike everyone you know (including family members) — you have never felt comfortable in a specific vocational slot?

Seeing as you are one of my readers, someone who has made it to Chapter 13 of this highly-technical, offbeat and unconventional book, and you are actually reading the answers to the exercises at the end of that chapter, my guess is that you have often wondered, "Just where, if anywhere, do I fit in?"

If so, what I want you to do right now is take a break from your work and read the science fiction novella Profession by Isaac Asimov.

The story first appeared in the in the July 1957 issue of the magazine "Astounding Science Fiction", and in 1959 it was published as part of the collection of Asimov stories in the book "Nine Tomorrows" (where I first found it).

It will take you a while to read the story (it is a novella) but I promise you, it will be well worth it.

By the time you finish Profession, you will begin to understand that you are special in a rare but important way. This, in turn, will make you feel a better about yourself, and you will be patient about the way in which your life seems to be unfolding.

Here are two different places where you can read the story Profession:

read "Profession" from site #1

read "Profession" from site #2

Along the way, you will find out the significance of living in a House for the Feeble-Minded.

Character Chapter Name Purpose
{ }24bracesbrace expansion: generate a pattern of characters
|15pipecommand line: create a pipeline
<15less-thancommand line: redirect input
>15greater-thancommand line: redirect output
( )15parenthesescommand line: run commands in a subshell
#14hash, poundcommand line: start of comment, ignore rest of line
;10semicoloncommand line: separates multiple commands
`13backquotecommand line: command substitution
~24tildefilename expansion: insert name of home directory
?24question markfilename expansion: match any single character
[ ]24bracketsfilename expansion: match from a set of characters
*24starfilename expansion: match zero or more characters
!13banghistory list: event marker
&26ampersandjob control: run command in background
\12backslashquoting: escape the next character
'12quote, single quotequoting: suppress all substitutions
"12double quotequoting: suppress most substitutions
{ }12bracesvariables: delimit a variable name
$12dollarvariables: substitute the value of a variable
<Return>7newlinewhitespace: mark the end of a line
<Tab>10tabwhitespace: separate words within the command line
<Space>10spacewhitespace: separate words within the command line
Character Chapter Name Purpose

Review Question #2:

Within the world of Unix, some characters have nicknames. For example, an apostrophe is usually referred to as a "quote" or a "single quote". What are the nicknames Unix people use for the following characters:

• Asterisk
• Enter/return
• Exclamation mark
• Period
• Quotation mark
• Vertical bar

Answer

CharacterNickname
Asterisk Star
Enter/return Newline
Exclamation mark Bang
Period Dot
Quotation mark Double quote
Vertical bar Pipe

Review Question #3:

What are the three different ways to quote characters? How do they differ?

Answer

Use a backslash to quote a single character. (When you do this, we say that you "escape" the character.)

Use single quotes to quote a string of characters.

Use double quotes to quote a string of characters, but to keep the special meaning of $ (dollar), ` (backquote) and \ (backslash).

Review Question #4:

What is a builtin command?

Where do you find the documentation for a builtin command?

Answer

A builtin command, also called an internal command or a builtin, is a command that is interpreted directly by the shell.

Builtin commands are documented in one of two places: the man page for the shell, or a special man page for all the builtins. Unlike external commands, builtin commands do not have their own man pages.

Review Question #5:

What is the search path?

How can you display your search path?

Answer

The search path is the list of directories in which the shell looks when it needs to find a program that must be executed.

To display your search path, use

echo $PATH

Review Question #6:

What is the history list?

The simplest, most common use of the history list is to re-execute the previous command. How do you do this?

Using Bash or the Tcsh, how would you recall, edit, and then execute the previous command?

Answer

When you use the shell, the history list is a list of the commands that have been entered. You can access the history list in a variety of ways — the details depend on the shell is being used — in order to recall previous commands, which can then be modified and reentered.

To re-execute the previous command with Bash, the Tcsh and the C-Shell, enter !!. With the Korn Shell, enter fc -s.

With Bash or the Tcsh, the easiest way to edit and then execute the previous command, is to press the <Up> key to recall the command, make any changes you want, and then press <Return>.

Review Question #7:

What is autocompletion?

How many different types of autocompletion are there?

Explain briefly what each type of autocompletion does.

Which type of autocompletion is the most important?

Answer

Autocompletion is a feature of the shell that helps the user enter commands by automatically completing words.

There are six types of autocompletion. They are used to complete the names of...

• Filename completion → files and directories
• Command completion → commands, including pathnames
• Variable completion → variables
• Userid completion → userids on your system
• Hostname completion → computers on your local network

Filename completion is the most important. It is the only type of autocompletion that is supported by all four major shells (Bash, Korn shell, C-Shell, and the Tcsh).

Applying Your Knowledge #1:

How do you modify the Bash shell prompt to display your userid, the working directory, and the current time?

How do you do the same for the Tcsh shell prompt?

Answer

Bash:

export PS1="\u \w \@ $ "

Tcsh:

set prompt = "%n %~ %@ %"

Applying Your Knowledge #2:

What is command substitution?

Use command substitution to create a command that displays "These userids are logged in right now:" followed by a list of the userids.

Answer

Command substitution is a feature of the shell that enables you to specify that the output of one command is to be inserted into another command, which is then executed. To use command substitution, you enclose the first command in backquote (`) characters. For example:

echo "These userids are logged in right now:" `users`

Applying Your Knowledge #3:

Enter the command:

echo "I am a very smary person."

Using a history list tool, change this command to correct the spelling of "smart".

Answer

After you enter the command and press <Return>, you can make the correction by entering:

^ry^rt

Note: In this case, ^r means to type a circumflex followed by the lowercase letter "r". It does not mean to press <Ctrl-R>.

Applying Your Knowledge #4:

Your working directory contains the following files (only):

datanew dataold important phonenumbers platypus

Using autocompletion, what are the minimum number of characters you need to type to reference each of the files?

Answer

datan<Tab>datanew
datao<Tab>dataold
i<Tab>important
ph<Tab>phonenumbers
pl<Tab>platypus

For Further Thought #1:

In this chapter, we have discussed several tools that help you enter commands quickly: the history list, autocompletion and aliases. These tools are complicated and take time to master. Some people can't be bothered to put in the time because, to them, it is not worth the effort. Other people embrace such tools with alacrity.

What type of person has a strong need to enter commands as quickly as possible?

Answer

The type of person who has a strong need to enter commands as quickly as possible is an intelligent person with has high ideaphoria (flow of ideas) and low finger dexterity.

For Further Thought #2:

What are the advantages of creating a great many specialized aliases? What are the disadvantages?

Answer

Advantages:

• You will have a fast, comfortable working environment.

• You can create an environment suitable for your particular habits.

Disadvantages:

• You will have trouble when you need to move to another system that does not have your customizations.

• You will never become comfortable with the standard features that you choose to bypass. For example, if you include options with your aliases, you may never memorize those options.

Jump to top of page