This is an old revision of the document!
The URL style of this wiki was changed. All old URLs should continue to work, but please update your links. New base is http://wiki.bash-hackers.org
The Bash-Hackers Wiki This wiki is intended to hold documentations of any kind about the GNU Bash. The main motivation was to provide human-readable documentation and information to not force users to read every bit of the Bash manpage - which is hard sometimes. However, these docs here are not meant as newbie tutorial.
What would YOU like to see here? (outdated and locked, please use the discussions)
Stranger! Feel free to register and edit the contents. There is a Bash Hackers Wiki needs love page that lists some things to do. The registration is only there to prevent SPAM.
Bash version 4 is here! New information is being merged into this documentation step by step. The logo
indicates Bash version 4 features or behaviour. There is also a small text about the interesting changes: Bash 4 - a rough overview
Scripting with style – an assorted collection of style and optic hintsThere is a section that holds small code snipplets.
See also some Bash source code excerpts.
Doing specific tasks: concepts, ways, ideas:
Compound commands
| Compound commands overview | |
|---|---|
| Grouping | |
{ …; } | command grouping |
( … ) | command grouping in a subshell |
| Conditionals | |
[[ ... ]] | conditional expression |
if …; then …; fi | conditional branching |
case … esac | pattern-based branching |
| Loops | |
for word in …; do …; done | classic for-loop |
for ((x=1; x<=10; x++)); do ...; done | C-style for-loop |
while …; do …; done | while loop |
until …; do …; done | until loop |
| Misc | |
(( ... )) | arithmetic evaluation |
select word in …; do …; done | user selections |
Expansions and substitutions
| Introduction to expansions and substitutions | |
|---|---|
{A,B,C} {A..C} | Brace expansion |
~/ ~root/ | Tilde expansion |
$FOO ${BAR%.mp3} | Parameter expansion |
`command` $(command) | Command substitution |
<(command) >(command) | Process substitution |
$((1 + 2 + 3)) $[4 + 5 + 6] | Arithmetic expansion |
Hello <---> Word! | Word splitting |
/data/*-av/*.mp? | Pathname expansion |
This is a selection of builtin commands and command-like keywords, loosely arranged by their common uses. These are provided directly by the shell, rather than invoked as standalone external commands.
| Declaration commands Commands that set and query attributes/types, and manipulate simple datastructures. | Alt | Type | |
|---|---|---|---|
| declare | Display or set shell variables or functions along with attributes. | typeset | builtin |
| export | Display or set shell variables, also giving them the export attribute. | - | builtin |
| local | Declare variables as having function local scope. | - | builtin |
| readonly | Mark variables or functions as read-only. | declare -r | builtin |
| unset | Unset variables and functions. | - | builtin |
| I/O Commands for reading/parsing input, or producing/formatting output of standard streams. | Alt | Type | |
| coproc | Co-processes: Run a compound command in the background with async I/O. | - | keyword |
| echo | Create output from args. | - | builtin |
| mapfile | Create arrays from lines of input | readarray | builtin |
| printf | "advanced echo." | - | builtin |
| read | Build variables or arrays from input streams. | - | builtin |
| Configuration and Debugging Commands that modify shell behavior, change special options, assist in debugging. | Alt | Type | |
| caller | Identify/print execution frames. | - | builtin |
| set | Control positional parameters and shell behaviour. | - | builtin |
| shopt | set/get shell options. | - | builtin |
| Control flow and data processing Commands that operate on data and/or affect control flow. | Alt | Type | |
|---|---|---|---|
| continue / break | continue with or break out of loops. | - | builtin |
| let | Arithmetic evaluation - an old fashioned way. | - | builtin |
| return | Break out of a function, returning the specified exit status. | - | builtin |
| [ | The classic test command. | test | builtin |
| Process and Job control Commands related to jobs, signals, process groups, subshells. | Alt | Type | |
| exec | Replace the shell, set redirections. | - | builtin |
| trap | Set traps. | - | builtin |
| wait | Wait for background jobs and asynchronous lists. | - | builtin |
| Interactive History, programmable completion, directory stack. | Alt | Type | |
previous alphabetical version
| A-G | |
|---|---|
| caller | identify/print execution frames (Bash builtin) |
| coproc | Co-processes (Bash keyword) |
| declare | display or set shell variables or functions along with attributes (Bash builtin, synonym: typeset) |
| exec | replace the shell, set redirections (Bash builtin) |
| I-N | |
| let | arithmetic evaluation - an old fashioned way (Bash builtin) |
| mapfile | Mapping lines of input to an array, also named readarray (Bash builtin) |
| O-T | |
|---|---|
| printf | "advanced echo" (Bash builtin) |
| read | getting input from stdin (Bash builtin) |
| readonly | mark variables or functions as read-only (Bash builtin) |
| set | control positional parameters and shell behaviour (Bash builtin) |
| shopt | set/get shell options (Bash builtin) |
| test | the classic test command (Bash builtin) |
| U-Z | |
| unset | unset variables and functions (Bash builtin) |
| Statistics for Month: April 2012 | ||
|---|---|---|
| Rank | Views | Article |
| 1 | 6833 | Small getopts tutorial (March: 11663) |
| 2 | 4025 | The printf command (March: 7079) |
| 3 | 2861 | Quotes and escaping (March: 5730) |
| 4 | 2854 | The classic test command (March: 6145) |
| 5 | 2222 | Parameter expansion (March: 4540) |
| 6 | 1760 | Handling positional parameters (March: 3591) |
| 7 | 1249 | Bash 4 - a rough overview (March: –) |
| 8 | 1212 | Editing files with the ed text editor from scripts (March: 2727) |
| 9 | 1205 | The read builtin command (March: –) |
| 10 | 1182 | Lock your script (against parallel run) (March: –) |
lhunath is making a Bash Guide on Greg's wiki (designed for newbies)
Visits in irc.freenode.net, channel #bash
If you have critics or suggestions, please feel free to send a mail using the contact form on the right. If you have quick suggestions, you can also use the Wishlist (editable by everyone!). Note that there is a discussion platform below every article page.
Please also see the imprint if you have problems with the site and its contents (legality, …)!
It also would be nice to drop a line when
Simply: Reader's feedback