Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Metacharacters for the POSIX shell

&pagelevel(3)&pagelevel

Argument and command separators

Metacharacter

Meaning

Blank
Newline
Tab

Argument separators, depending on the value of the IFS variable

Newline

End of command

|

Pipe symbol

;

End of command

&

End of command; a command terminated with this symbol is run as a
background process

||

ORIF; the next command is executed only if the preceding command
returns a non-zero exit status

&&

ANDIF; the next command is executed only if the preceding command
returns an exit status of zero

Command grouping

Metacharacter

Meaning

(command_list)

Execute command_list in a subshell

{ command_list;}

Collect the output of all commands from command_list

Execute command and replace with output

Metacharacter

Meaning

`command`

Replace command with its output

$(command)

Replace command with its output

File name generation

Metacharacter

Meaning

*

As a pattern on its own:
replaced by the list of all file names in the current directory that do not begin
with a period (.).

As part of a pattern:
replaced by no, one or more character(s) depending on the file names which
match the pattern.

?

As a pattern on its own:
replaced by the list of all file names in the current directory that consist of
exactly one character, except for a period (.).

As part of a pattern:
replaced by no, one or more character(s) depending on the file names which
match the pattern.

[s]

Replaced by exactly one of the characters which are not contained in the string
s depending on the file names which match the pattern.

[c1-c2]

Replaced by any one character from the range between c1 and c2 inclusive to
match file names in the current directory.
c1 and c2 must be ordinary characters.
The characters which collate between c1 and c2 are determined by the EBCDIC
collating sequence.
Expressions of type [s] and type [c1-c2] can be combined:
[s1c1-c2s2]

[!s]

Replaced by exactly one of the characters which are not contained in the string
s depending on the file names which match the pattern.

[!c1-c2]

Replaced by exactly one of the characters which do not lie in the range c1 to c2
depending on the file names which match the pattern (see [c1-c2]).
Expressions of type [!s] and type[!c1-c2] can be combined: [!s1c1-c2s2]

Redirection of standard output

Metacharacter

Meaning

[n]> file

Redirect standard output [or file descriptor n] to file, deleting original contents

[n]>> file

Redirect standard output [or file descriptor n] to file, retaining original contents
(append)

[n]> &digit

Redirect standard output [or file descriptor n] to the file associated with file
descriptor digit

[n]> &-

Close standard output [or file descriptor n]

Redirection of standard input

Metacharacter

Meaning

[n] <file

Redirect standard input [or file descriptor n] to file

[n] <<argument

Start a "here" document or redirect to file descriptor n

[n] <<-argument

Start a "here" document or redirect to file descriptor n; stripping leading tabs

[n] <&digit

Redirect standard input to the file [or file descriptor n] associated with file
descriptor digit

[n] <&-

Close standard input [or file descriptor n]

[n] <>file

file [or file descriptor n] is opened as the standard input for reading and writing

Shell variables and parameters

Metacharacter

Meaning

name=value

Assign a value to the variable name

$name

Value of the variable name; keyword parameter

${name}

Like $name; the braces separate the variable name from following
figures or characters

${name-default_value}

Replace with default_value if name is undefined

${name=default_value}

Assign default_value if name is undefined

${name?default_value}

Shell terminates process execution with error message
parameter : default_value if name is undefined

${name+default_value}

Replace with the null string if name is undefined;
replace with default_value if name is defined

${name:-default_value}

Replace with default_value if name is undefined or if its value is the
null string

${name:=default_value}

Assign default_value if name is undefined or if its value is the null
string

${name:?default_value}

Shell terminates process execution with error message
parameter : default_value if name is undefined or if its value is the
null string

${name:+default_value}

Replace with the null string if name is undefined or if its value is the
null string;
replace with default_value if name is undefined or if its value is the
null string

${#name}

Replace with the length of the string formed by name. If name is one
of the characters * or commercial at @ then the substitution is
undefined

${name%pattern}

If the POSIX shell pattern pattern matches the end of the value of
name, then the substitute text is formed from the value of name
without the deleted segment which corresponds to pattern. The
shortest matching pattern is deleted.

${name%%pattern}

If the POSIX shell pattern pattern matches the end of the value of
name, then the substitute text is formed from the value of name
without the deleted segment which corresponds to pattern. The
shortest matching pattern is deleted.

${name#pattern}

If the POSIX shell pattern pattern is to match the start of the value
of name, then the substitute text is formed from the value of name
from which the segment which corresponds to pattern has been
deleted. The shortest matching pattern is deleted.

${name##pattern}

If the POSIX shell pattern pattern is to match the start of the value
of name, then the substitute text is formed from the value of name
from which the segment which corresponds to pattern has been
deleted. The shortest matching pattern is deleted.

$0

0th command-line argument, i.e. the name of the command, the
shell script or the current shell

$1, $2, ... , $9

Positional parameters

$*
"$*"

All command-line arguments
All command-line arguments as a single argument

$@
"$@"

All command-line arguments
All command-line arguments as separate arguments

$#

Number of command-line arguments, excluding $0

$$

Process ID (PID) of the current shell

$!

PID of the last command run in the background

$?

Exit status of the last executed command that was not run in the
background

$-

All options set in the current shell

Shell functions

Metacharacter

Meaning

name() { command_list;}

Shell function; when name is invoked, the commands from
command_list are executed

Quoting metacharacters

Metacharacter

Meaning

\

'...'

"..."

Escapes the following metacharacter

Escapes all metacharacters between quotes; treat as a single argument

Does not escape the metacharacters $ `...` \
Treat as a single argument

Miscellaneous

Metacharacter

Meaning

#

;;

Comment character in shell scripts

Command list terminator within case constructs

~
~-
~+

Tilde substitution

(( ))
$((expression))

Arithmetic evaluation

[[ ]]

Conditional expressions