Export Pathpathusrfrobulatorbin

to one of the startup files such as the user-specific bash configuration file .bashrc in your home directory.

i- ■ i■ . Any environment variable preceded by a dollar sign ($) means that you are referring to the value of that variable, not its name. That is why the command shown previously, in which we changed PATH, works. We are changing the value of PATH to be its old value ($PATH) with the : and the additional path appended to it.

r : r. When you've set an environment variable, you can unset it at any time using the i-.-.,".unset command. The unset command removes the environment variable and its associated value from the shell in which you execute it. You would not want to unset an environment variable such as the PATH environment variable because the shell would not know where to find commands. But occasionally, you may want to unset an environment variable, particularly one that defines default options or arguments for a particular command. For example, in the output of printenv shown earlier, you see MORE=-sl. That means that the option -sl (which removes multiple blank lines from the file being viewed and suppresses the expression of the form feed character) will be passed to the pager program more whenever it is run. If you unset the environment variable MORE, it will run without these options.

Wildcards and Pattern Matching

All Unix and Linux shells support several ways of locating file and directory names that match a specified pattern. As you might expect, when working from the command line, one of the most common things that you will want to do is to specify the names of one or more files as arguments to other commands. To make it easier to identify specific files without requiring that you type every filename in its entirety, Linux shells provide a number of different ways to specify patterns that can be used to match specific filenames.

The most basic pattern matching provided by Linux shells such as bash are two special characters known as wildcards, which means that these characters can match any other character. Linux shells support two basic wildcards:

■ Asterisk (*): Also referred to as the star, can represent any number of characters (including none at all) in a row

■ Question mark (?): Represents any single character

In addition to these wildcards, Linux shells support two other ways to match specific patterns within filenames:

■ By specifying ranges of values separated by a dash within square brackets. For example, the expression [1-3] will match any instance of the numbers from 1 to 3, inclusive.

■ By specifying lists of comma-separated values enclosed within braces (also known as curly brackets). For example, the expression {1,3} will match either the number 1 or the number 3.

A few examples will help clarify how you can use these to identify certain files in your directories. Suppose that a directory contains the following files:

TABLE 2-1

PATTERN

Pattern Matching in Linux Shells

MATCHING FILENAMES

PATTERN

*

fi fi

lei, file1.doc, file2, file2.doc, file3, le3.txt, fi1e8, other_file.doc

file?

fi

lei, fi 1 e2, fi 1 e3, file8

*. doc

fi

lei.doc, file2.doc, other_file.doc

file7.doc

fi

lei.doc, file2.doc

fi le?.*

fi

lei.doc, file2.doc, file3.txt

file[l-3]

fi

lei, fi 1 e2, fi 1 e3

f i 1 e{l, 3}

fi

lei, fi 1 e3

Was this article helpful?

0 0

Post a comment