Skip to Main Content
Learning the Korn Shell, 2nd Edition
book

Learning the Korn Shell, 2nd Edition

by Arnold Robbins, Bill Rosenblatt
April 2002
Beginner content levelBeginner
432 pages
18h 29m
English
O'Reilly Media, Inc.
Content preview from Learning the Korn Shell, 2nd Edition

Chapter 6. Command-Line Options and Typed Variables

You should have a healthy grasp of shell programming techniques now that you have gone through the previous chapters. What you have learned up to this point enables you to write many nontrivial, useful shell scripts and functions.

Still, you may have noticed some remaining gaps in the knowledge you need to write shell code that behaves like the Unix commands you are used to. In particular, if you are an experienced Unix user, it might have occurred to you that none of the example scripts shown so far have the ability to handle options (preceded by a dash (-)) on the command line. And if you program in a conventional language like C or Pascal, you will have noticed that the only type of data that we have seen in shell variables is character strings; we haven’t seen how to do arithmetic, for example.

These capabilities are certainly crucial to the shell’s ability to function as a useful Unix programming language. In this chapter, we show how the Korn shell supports these and related features.

Command-Line Options

We have already seen many examples of the positional parameters (variables called 1, 2, 3, etc.) that the shell uses to store the command-line arguments to a shell script or function when it runs. We have also seen related variables like * and @ (for the string(s) of all arguments) and # (for the number of arguments).

Indeed, these variables hold all the information on the user’s command line. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning the Korn Shell

Learning the Korn Shell

Bill Rosenblatt
Unix Power Tools, 3rd Edition

Unix Power Tools, 3rd Edition

Jerry Peek, Shelley Powers, Tim O'Reilly, Mike Loukides

Publisher Resources

ISBN: 0596001959Supplemental ContentErrata Page