Skip to Content
Learning the bash Shell, 3rd Edition
book

Learning the bash Shell, 3rd Edition

by Cameron Newham
March 2005
Beginner content levelBeginner
352 pages
16h 9m
English
O'Reilly Media, Inc.
Content preview from Learning the bash Shell, 3rd Edition

Appendix D. Programmable Completion

Programmable completion is a feature that was introduced in bash 2.0.[1] It extends the built-in textual completion that is discussed in Chapter 2 by providing hooks into the completion mechanism. This means that it is possible to write virtually any form of completion desired. For instance, if you were typing the man command, wouldn’t it be nice to be able to hit TAB and have the manual sections listed for you. Programmable completion allows you to do this and much more.

This Appendix will only look at the basics of programmable completion. While completion is a feature you are very likely to use in everyday shell operation, you are unlikely to need to delve into the inner depths and actually write your own completion code. Fortunately the feature has been around for some time and there are already several libraries of completion commands developed by other people. We’ll just outline the basic commands and procedures needed to use the completion mechanism should you ever need to work on it yourself.

In order to be able to do textual completion in a particular way you first have to tell the shell how to do it when you press the TAB key. This is done via the complete command.

The main argument of complete is a name that can be the name of a command or anything else that you want textual completion to work with. As an example we will look at the gunzip command that allows compressed archives of various types to be uncompressed. Normally, if you ...

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

Bash Shell Scripting, 2nd Edition

Bash Shell Scripting, 2nd Edition

Sander van Vugt

Publisher Resources

ISBN: 0596009658Errata Page