Harley Hahn's Guide to
|
A Personal Note
Chapters...
Command
INSTRUCTOR |
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
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?
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)
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
Disadvantages:
• Non-standard
Exercises: Introduction | Chapter list
© All contents Copyright 2024, Harley Hahn
|