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 10...

Command Syntax

Review Question #1:

How do you enter more than one command on the same line?

Answer

Separate the commands with a semicolon, for example:

date; users; uptime
date ; users ; uptime

Review Question #2:

The syntax of a Unix command can be expressed in the form:

command-name options arguments

What are options? What are arguments?

Answer

An option is a part of a command, almost always prefaced with - or -- (one or two hyphens), that specifies how you want the command to execute.

A argument is an item that is used to pass information to the program you want to run.

Review Question #3:

What are dash options and dash-dash options?

What is each type used for?

Answer

For almost all commands, options start with either a single hyphen or two hyphens. The single-hyphen options (for example, -h) are called "dash options". The double-hyphen options (for example, --help) are called "dash-dash options".

The dash options are the original options that have always been used with Unix. The dash- dash options are used only with the GNU utilities (see Chapter 2). The chief purpose is to use longer option names, which makes the options easier to understand and remember.

On the other hand, longer options are slower to type and a lot easier to misspell. For this reason, many commands give you a choice by giving the same option a short and a long name. This allows you to use whichever one you want.

Review Question #4:

What is whitespace?

Answer

When using the shell, "whitespace" refers to one or more consecutive spaces or tabs.

With some programs, the definition of whitespace is expanded to include newlines as well as spaces and tabs.

Review Question #5:

When you learn the syntax of a new program, what are the three basic questions you should ask?

Answer

A good approach to learning the syntax for a new command is to answer the following three questions:

• What does the command do?
• How do I use the options?
• How do I use the arguments?

Applying Your Knowledge #1:

It is often desirable to enter more than one command on the same line. Create a short summary of your system's status by typing the following three commands on a single line:

date (time and date)
users (userids that are logged in)
uptime (how long your system has been up)

Answer

date; users; uptime

Applying Your Knowledge #2:

Write the syntax for the following program. The command name is foobar. There are three options -a, -b and -c. The -c option takes an optional argument named value. Finally, there must be one or more instances of an argument named file.

Answer

foobar [-ab] [-c [value...]] file...

For Further Thought #1:

Many of the GNU utilities (used with Linux and FreeBSD) support both the traditional, abbreviated - (dash) options, as well as the longer -- (dash-dash) options. Why did the GNU developers feel it was necessary to introduce a new style of options?

What are the advantages? What are the disadvantages?

Answer

When the GNU utilities were being developed (see Chapter 2), the designers wanted to be able to use longer option names. However, longtime conventions dictated that all options should be only a single character, usually a letter, and that multiple options should be able to be combined (for example, ls -ltd).

It would be possible to modify the rules, but that would be a drastic change that would invalidate many existing programs, and force too many people to change their habits. Instead, it was decided that longer options would be allowed, as long as they were preceded by two hyphens, instead of one. In that way, the system could be expanded without compromising what already existed.

Advantages:

• Allows new options
• Easy to read
• Self-documenting (good for shell scripts)

Disadvantages:

• Non-standard
• Creates compatibility problems
• Take longer to type

Jump to top of page