Making the Most of Bash

Basically, in a Bash environment an administrator is working with commands. An example of such a command is ls, which you can use to display a list of files in a given directory. To make working with these commands as easy as possible, Bash has some useful features to offer. Some of the most used Bash features are automatic completion and the history mechanism.

Some shells offer the option to complete a command automatically. Bash also has this feature but goes beyond the option to just complete commands. Bash can complete almost everything— not just commands but also filenames and shell variables.

Note A variable is a common value, stored with a given name, that is used often by the shell and by the commands working from the shell. An example of such a variable is PATH, which stores a list of directories that should be searched when a user enters a command. To refer to the contents of a variable, prepend a $ sign before the name of the variable. For example, the command echo $PATH would display the content of the current search path Bash is using.

To use the completion feature, press the Tab key. The following is an example of how this works. In this example, the cat command displays the contents of an ASCII text file. The name of this file, which is in the current directory, is this_is_a_file. To open this file, the user can type cat thi and next press the Tab key. If just one file starts with the letters thi, Bash will automatically complete the name of the file. If there are more options, Bash will complete the name of the file as far as possible. This happens, for example, when the current directory contains files with the names this_is_a_text_file and thisAlsoIsAFile. Since both files start with this, Bash will complete only up to this and not go beyond that. To display a list of possibilities, you can then hit the Tab key again. This allows you to manually enter more information. Of course, you can then pressing the Tab key again to use the completion feature once more.

Was this article helpful?

0 0

Post a comment