start page | rating of books | rating of authors | reviews | copyrights

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 8.18 Here Documents Chapter 8
How the Shell Interprets What You Type
Next: 8.20 How Many Backslashes?
 

8.19 "Special" Characters and Operators

Before you learn about regular expressions (26.1), you should understand how quoting (8.14) works in UNIX.

Regular expressions use metacharacters. The shells also have metacharacters. Metacharacters are simply characters that have a special meaning. The problem occurs when you want to use a regular expression in a shell script. Will the shell do something special with the character? Or will it be passed unchanged to the program? The $ character is a good example. It could be the beginning of a variable name or it could bepart of a regular expression . (26.2) If you need a regular expression, you must know if any of the characters of the expression are metacharacters, and must know the right way to quote that character so that it is passed to the program without being modified by the shell.

Table 8.3 is a table of special characters and operators in the C shell (csh) and Bourne shell (sh). The chart also includes several combinations of characters just to be complete. As in other parts of this book, the sh entries apply to ksh and bash; the csh entries apply to tcsh.

Table 8.3: List of Special Characters and Their Meanings
CharacterWhereMeaningArticle
ESCcshFilename completion.9.8
RETURNcsh, shExecute command.41.2
spacecsh, shArgument separator.8.5
TABcsh, shArgument separator.8.5
TABbashFilename completion.9.8
#csh, shStart a comment.44.2
`csh, shCommand substitution (backquotes).9.16
"shWeak quotes.8.14
"cshWeak quotes.

8.15, 8.14

'shStrong quotes.8.14
'cshStrong quotes.

8.15, 8.14 See \.

\shSingle-character quote.8.14
\cshSingle-character quote.

8.15, 8.14

$varcsh, shVariable.

6.1, 6.8

${var}csh, shSame as $var.6.8
$var:modcshEdit var with modifier mod9.6
${var-default}sh

If var not set, use default.

45.12
${var=default}sh

If var not set, set it to default and use that value.

45.12
${var+instead}sh

If var set, use instead. Otherwise, null string.

45.12
${var?message}sh

If var not set, print message (else default). If var set, use its value.

45.12
${var#pat}ksh, bash

Value of var with smallest pat deleted from start.

9.7
${var##pat}ksh, bash

Value of var with largest pat deleted from start.

9.7
${var%pat}ksh, bash

Value of var with smallest pat deleted from end.

9.7
${var%%pat}ksh, bash

Value of var with largest pat deleted from end.

9.7
|csh, shPipe standard output.

1.4, 13.1

|&cshPipe standard output and standard error.13.5
^sh onlyPipe character (obsolete).
^csh, bashEdit previous command line.11.5
&csh, shRun program in background.

1.27, 1.28

?csh, shMatch one character.

1.16, 15.2

*csh, shMatch zero or more characters.

1.16, 15.2

;csh, shCommand separator.8.5
;;shEnd of case statement.44.5
~csh, ksh, bashHome directory.14.11
~usercsh, ksh, bashHome directory of user.14.11
!csh, bashCommand history.11.2
-ProgramsStart of optional argument.8.5
-Programs

Read standard input. (Only certain programs.)

13.13
$#csh, shNumber of arguments to script.44.15
"$@"shOriginal arguments to script.44.15
$*csh, shArguments to script.44.15
$-shFlags set in shell.2.11
$?shStatus of previous command.44.7
$$csh, shProcess identification number.8.14
$!sh

Process identification number of last background job.

7.12
$<cshRead input from terminal.9.11
cmd1 && cmd2csh, sh

Execute cmd2 if cmd1 succeeds.

44.9
cmd1 || cmd2csh, sh

Execute cmd2 if cmd1 fails.

44.9
$(..)ksh, bashCommand substitution.

45.31, 9.16

((..))ksh, bashArithmetic evaluation.
\. filesh

Execute commands from file in this shell.

44.23
:shEvaluate arguments, return true.45.9
:shSeparate values in paths.

6.4, 14.5, 21.8

:cshVariable modifier.9.6
[]csh, shMatch range of characters.

1.16, 15.2

[]shTest.44.20
%jobcsh, ksh, bashIdentify job number.12.1
(cmd;cmd)csh, shRun cmd;cmd in a subshell.13.7
{}csh, bashIn-line expansions.

9.5

{cmd;cmd; }sh

Like (cmd;cmd) without a subshell.

13.8
>filecsh, shRedirect standard output.13.1
>>filecsh, shAppend standard output.13.1
<filecsh, shRedirect standard input.13.1
<<wordcsh, sh

Read until word, do command and variable substitution.

8.18, 9.14

<<\wordcsh, sh

Read until word, no substitution.

8.18
<<-wordsh

Read until word, ignoring leading TABs.

8.18
>>! filecsh

Append to file, even if noclobber set and file doesn't exist.

13.6
>! filecsh

Output to file, even if noclobber set and file exists.

13.6
>| fileksh, bash

Output to file, even if noclobber set and file exists.

13.6
>& filecsh

Redirect standard output and standard error to file.

13.5
m> filesh

Redirect output file descriptor m to file.

45.21
m>> filesh

Append output file descriptor m to file.

m< filesh

Redirect input file descriptor m from file.

<&msh

Take standard input from file descriptor m.

<&-shClose standard input.45.10
>&msh

Use file descriptor m as standard output.

45.21
>&-shClose standard output.45.21
m<&nsh

Connect input file descriptor n to file descriptor m.

45.22
m<&-shClose input file descriptor m.45.21
n>&msh

Connect output file descriptor n to file descriptor m.

45.21
m>&-shClose output file descriptor m.45.21

- BB, JP


Previous: 8.18 Here Documents UNIX Power ToolsNext: 8.20 How Many Backslashes?
8.18 Here Documents Book Index8.20 How Many Backslashes?

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System