0% found this document useful (0 votes)
63 views2 pages

OSDC - Cheatsheet-Metacharacters-2023 02 09

This document provides a cheat sheet for metacharacters and control operators used in Bash and other shells. It details common metacharacters like $, &, | and ; and their functions. It also covers redirection, wildcards, escape sequences and other special characters and their usage.

Uploaded by

doudoustaff
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views2 pages

OSDC - Cheatsheet-Metacharacters-2023 02 09

This document provides a cheat sheet for metacharacters and control operators used in Bash and other shells. It details common metacharacters like $, &, | and ; and their functions. It also covers redirection, wildcards, escape sequences and other special characters and their usage.

Uploaded by

doudoustaff
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

By Seth Kenlon,

Metacharacters Cheat Sheet David Both,


Don Watkins

Metacharacters are symbols with special meanings for Bash and other shells. They aren't
interpreted literally by the shell, but change the way the shell processes input and output.

Metacharacters and control operators


~ Tilde Home directory
$ Dollar sign Denote a variable (as in $HOME or $USER)
& Ampersand Run a command in the background
; Semi-colon Command termination
&& Double ampersand Continue to the next command upon success (AND)
|| Double pipe Continue to the next command upon failure (OR)
| Pipe Use output of the first command as input for the next
' Single-quote Treat all contents as literal
" Quote Treat spaces as literal, but expand variables
\ Backslash Treat the next character as literal
( ) Parentheses Execute contents in a subshell
{ ;} Braces Execute in current shell (terminate with semi-colon)
[ ] Brackets Test expression
(( )) Double parentheses Evaluate contents as a mathematical expression
[[ ]] Double brackets Test expression, returning 0 or 1

Redirection
> Overwrite existing content <
>> Append to existing content <<

opensource.com @opensourceway • Fosstodon.org/@osdc CC BY-SA 4.0


By Seth Kenlon,
Metacharacters Cheat Sheet David Both,
Don Watkins

Wildcards
? Match exactly one of any character
* Match zero or more of any character

Ranges
[0-9] Any digit
[a-z] Any lowercase alpha
[A-Z] Any uppercase alpha
[a-zA-Z] Any lowercase or uppercase alpha
[abc] Only a, b, and c
[!a-z] No lowercase alpha
[!1-3] No 1, 2, or 3, but all other digits
[b-hot] Lowercase b through h, and the letter o and the letter t
[A-M0-9] Uppercase alpha A through M, and any digit

Escape sequences

Escape sequences are interpreted as commands by the shell.


\b Backspace echo a$'\b'b
\e Escape echo a$'\e'b
\f Form feed (like a non-returning newline) echo a$'\f' b
\n Newline echo a$'\n' b
\r Carriage return echo a$'\r' b
\t Horizontal tab echo a$'\t'b
\v Vertical tab echo a$'\v'b
\\ Backslash echo a$'\\'b
\cx Control-X echo a$'\cH'b
\uHHHH Unicode character of hexadecimal value HHHH echo a$'\u0259'
\NNN 8-bit character with octal value NNN echo a$'\451'

opensource.com @opensourceway • Fosstodon.org/@osdc CC BY-SA 4.0

You might also like