The shell lets you use a shorthand notation to include the values of certain things in the command line.
The shell does the following substitutions, in this order:
Let's look at these in more detail:
For example, ~mary/some_file refers to some_file in the home directory of the user named mary. If you don't specify a user name, it's assumed to be yours, so ~/some_file refers to some_file in your home directory.
echo $PATH
$(command)
or with the older form, using backquotes:
`command`
For example, to search all of your C files for a given string, type:
grep string $(find . -name "*.c")
The find command searches the given directory (. in this case) and any directories under it for files whose names end in .c. The command substitution causes grep to search for the given string in the files that find produces.
$(( expression ))
For example:
echo $((5 * 7))
[prefix]{str1,…,strN}[suffix]
where commas (,) separate the strings. For example, my_file.{c,o} expands to my_file.c my_file.o.
| If you want to: | Use this wildcard: |
|---|---|
| Match zero or more characters | * |
| Match any single character | ? |
| Match any characters (or range of characters separated by a hyphen) specified within the brackets | [] |
| Exclude characters specified within brackets | ! |
The following examples show you how you can use wildcards with the cp utility to copy groups of files to a directory named /tmp:
| If you enter: | The cp utility copies: |
|---|---|
| cp f* /tmp | All files starting with f (for example, frd.c, flnt) |
| cp fred? /tmp | All files beginning with fred and ending with one other character (for example, freda, fred3) |
| cp fred[123] /tmp | All files beginning with fred and ending with 1, 2, or 3 (that is, fred1, fred2, and fred3) |
| cp *.[ch] /tmp | All files ending with .c or .h (for example, frd.c, barn.h) |
| cp *.[!o] /tmp | All files that don't end with .o |
| cp *.{html,tex} | All files that end with .html or .tex |