Bash (Unix shell): Difference between revisions

Content deleted Content added
m Line-break protection.
m fix quot; repair
 
Line 1:
{{Short description|GNU replacement for the Bourne shell}}
{{Redirect|Bash (software)|other software|Bash (disambiguation)}}
{{multiple issues|
{{how-to|date=August 2025}}
{{More refs|date=August 2025}}
{{Over-quotation|date=August 2025}}
}}
{{Use dmy dates|date=March 2014}}
{{Infobox software
| nameauthor = [[Brian =Fox (programmer)|Brian BashFox]]
| logocaption = =
| screenshotdeveloper = [[Image:BashChet demo.png|250px]]Ramey
| captiongenre = Screenshot of= Bash[[Shell and(computing)]], [[BourneUnix shell|sh]], sessions[[command demonstrating some featureslanguage]]
| authorlanguage = Multilingual = ([[Brian Fox (computer programmer)|Brian Foxgettext]])
| latest release date = {{Wikidata| qualifier| preferred| single| Q189248| P348| P548 = Q2804309| P577}}
| released = {{start date and age|1989|6|7}}
| latest release version = {{Wikidata| property| preferred| references| edit| Q189248| P348| P548 = Q2804309}}
| frequently updated = yes
| license = {{Plainlist|
| programming language = [[C (programming language)|C]]
* v.4.0+: [[GNU General Public License#Version 3|GPL-3.0-or-later]]<ref>
| operating system = [[Cross-platform]]
{{Cite web
| access-date = 8 August 2025
| archive-date = 26 April 2019
| archive-url = https://web.archive.org/web/20190426210620/http://www.gnu.org/software/bash/
| publisher = [[GNU Project]]
| quote = Bash is free software, distributed under the terms of the [GNU] General Public License as published by the Free Software Foundation, version 3 of the License (or any later version).
| title = GNU Bash
| url = https://www.gnu.org/software/bash/
| url-status = live
| website = [[Free Software Foundation, Inc.]]
}}
</ref>
* v.1.11 – v.3.2: [[GNU General Public License#Version 2|GPL-2.0-or-later]]<ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 15 October 2021
| archive-url = https://web.archive.org/web/20211015233550/http://www.oldlinux.org/Linux.old/bin/old/bash-1.11/
| quote = See test.c for GPL-2.0-or-later
| title = bash-1.11
| url = https://www.oldlinux.org/Linux.old/bin/old/bash-1.11/
| url-status = dead
| website = oldlinux.org
}}
</ref>
* v.0.99 – v.1.05: [[GNU General Public License#Version 1|GPL-1.0-or-later]]<ref
name = bashfaq061>
{{Cite web
| access-date = 8 August 2025
| archive-date = 2 March 2021
| archive-url = https://web.archive.org/web/20210302212811/https://mywiki.wooledge.org/BashFAQ/061
| title = BashFAQ/061: Is there a list of which features were added to specific releases (versions) of Bash?
| url = https://mywiki.wooledge.org/BashFAQ/061
| url-status = live
| website = wooledge.org
}}
</ref><ref>
{{Multiref2|
{{Cite web
| access-date = 8 August 2025
| archive-date = 6 May 2021
| archive-url = https://web.archive.org/web/20210506191114/http://www.oldlinux.org/Linux.old/bin/old/bash-1.05/
| title = bash-1.05
| url = https://www.oldlinux.org/Linux.old/bin/old/bash-1.05/
| url-status = dead
| website = oldlinux.org
}}
|
{{ Cite web
| access-date = 8 August 2025
| title = Is there a way to download the presumably initial bash source bash-0.99?
| url = https://unix.stackexchange.com/questions/243375/is-there-a-way-to-download-the-presumably-initial-bash-source-bash-0-99
| website = unix.stackexchange.com
}}
}}
</ref>
}}
| logo = Gnu-bash-logo.svg
| name =
| operating system = {{UBL| [[Linux]] | [[Unix-like]] | [[macOS]] | [[Windows]] | [[Android (operating system)|Android]] | [[Oracle Solaris]] }}
| platform = [[GNU]]
| programming language = English,[[C multilingual(programming ([[gettextlanguage)|C]])
| statusreleased = {{start =date and age |8 June Active1989}}
| genre screenshot = [[Unix shell]]
| sourcewebsite model = [[Free = {{URL|www.gnu.org/software]]/bash/}}
}}
| license = [[GPLv3|GNU General Public License version 3]]+<ref name="license">{{cite web
 
| author = GNU Project
In [[Computer science|computing]], Bash is an interactive [[command-line interface| command interpreter]] and [[programming language]] developed for [[Unix]]-like [[operating systems]].<ref>
| authorlink = GNU Project
{{Cite web
| title = README file
| access-date = 15 August 2025
| url = http://www.gnu.org/software/bash/
| publisher = [[Encyclopædia Britannica]]
| quote = Bash is free software, distributed under the terms of the [GNU] General Public License as published by the Free Software Foundation, version 3 of the License (or any later version).
| title = operating system
| url = https://www.britannica.com/technology/operating-system
| website = britannica.com
}}
</ref><ref>
{{Cite web
| access-date = 8 August 2025
| publisher = IBM
| quote = The Bourne shell is an interactive command interpreter and command programming language.
| title = Bourne shell
| url = https://www.ibm.com/docs/en/aix/latest?topic=shells-bourne-shell
| website = ibm.com
}}
</ref>
It is designed as a 100% [[free software|free]] alternative for the [[Bourne shell]], `{{mono|sh}}`, and other proprietary [[Unix shells]].<ref>
{{Multiref2|
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| quote = The ultimate goal is to provide free software to do all of the jobs computer users want to do—and thus make proprietary software a thing of the past.
| title = GNU in a Nutshell
| url = https://www.gnu.org/gnu/about-gnu.html
| website = [[Free Software Foundation, Inc.]]
}}
|
{{Cite web
| access-date = 8 August 2025
| publisher = [[Free Software Foundation]]
| quote = The Free Software Foundation (FSF) is a nonprofit with a worldwide mission to promote computer user freedom.
| title = Free Software Foundation — working together for free software — Front Page
| url = https://www.fsf.org/
| website = fsf.org
}}
|
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| quote = GNU is an operating system which is 100% free software.
| title = GNU Software
| url = https://www.gnu.org/software/software.en.html
| website = [[Free Software Foundation, Inc.]]
}}
}}
</ref>
Bash has gained widespread adoption and is commonly used as the default [[login]] shell for numerous [[Linux]] distributions.<ref name = goftw2015>
{{Cite web
| access-date = 8 August 2025
| archive-date = 31 July 2020
| archive-url = https://web.archive.org/web/20200731032216/https://www.red-gate.com/simple-talk/opinion/geek-of-the-week/chet-ramey-geek-of-the-week/
| date = 14 December 2015
| first1 = Richard
| last1 = Morris
| title = Chet Ramey: Geek of the Week
| url = https://www.red-gate.com/simple-talk/opinion/geek-of-the-week/chet-ramey-geek-of-the-week/
| url-status = live
| work = Simple Talk
}}
</ref>
 
Created in 1989 by Brian Fox for the [[GNU Project]], it is supported by the [[Free Software Foundation]].<ref name = computerworld_08>
{{Multiref2|
{{Cite web
| access-date = 8 August 2025
| archive-date = 11 August 2016
| archive-url = https://web.archive.org/web/20160811002459/http://www.computerworld.com.au/article/222764/
| date = 30 March 2008
| first = Naomi
| last = Hamilton
| page = 2
| publisher = [[Computerworld |Computerworld Australia]]
| quote = When Richard Stallman decided to create a full replacement for the then-encumbered Unix systems, he knew that he would eventually have to have replacements for all of the common utilities, especially the standard shell, and those replacements would have to have acceptable licensing.
| title = The A-Z of Programming Languages: BASH/Bourne-Again Shell
| url = https://www.computerworld.com.au/article/222764/
| url-status = dead
| website = computerworld.com.au
}}
|
{{Cite web
| access-date = 8 August 2025
| date = 30 May 2008
| first = Naomi
| last = Hamilton
| publisher = [[Computerworld |Computerworld Australia]]
| title = The A-Z of Programming Languages: BASH/Bourne-Again Shell
| url = https://a-z.readthedocs.io/en/latest/bash.html
| website = readthedocs.io
}}
|
{{Cite web
| access-date = 8 August 2025
| date = 30 May 2008
| first = Naomi
| last = Hamilton
| publisher = University of South Carolina, CSCE 330 Programming Language Presentations
| title = The A-Z of Programming Languages: BASH/Bourne-Again Shell
| url = https://cse.sc.edu/~mgv/csce330f16/pres/az.pdf
| website = sc.edu
}}
}}
</ref>
Bash (short for "''Bourne Again SHell''") can operate within a terminal emulator, or [[terminal emulator|text window]], where users input commands to execute various tasks.<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| quote = Brian Fox has now completed GNU's version of sh, called BASH, the `Bourne Again SHell'.
| title = GNU's Bulletin, vol 1 no 7, June, 1989 :: GNU Project Status Report
| url = https://www.gnu.org/bulletins/bull7.html#SEC14
| website = [[Free Software Foundation, Inc.]]
}}
</ref><ref>
{{Multiref2|
{{Cite web
| access-date = 8 August 2025
| archive-date = 24 April 2011
| archive-url = https://web.archive.org/web/20110424064815/https://www.gnu.org/gnu/thegnuproject.html
| date = 12 November 2010
| first = Richard
| last = Stallman
| publisher = [[GNU Project]]
| quote = "Bourne Again Shell" is a play on the name ''Bourne Shell'', which was the usual shell on Unix.
| title = About the GNU Project (Footnote 5)
| url = https://www.gnu.org/gnu/thegnuproject.html
| url-status = live
| website = [[Free Software Foundation, Inc.]]
}}
|
{{Cite web
| access-date = 8 August 2025
| archive-date = 9 March 2011
| archive-url = https://web.archive.org/web/20110309092607/http://www.markus-gattol.name/ws/bash.html
| date = 10 January 2015
| df = dmy-all
| first = Markus
| last = Gattol
| quote = The name is a pun on the name of the Bourne shell (sh), an early and important Unix shell written by Stephen Bourne and distributed with Version 7 Unix circa 1978, and the concept of being 'born again'.
| title = Bourne-again Shell
| url = https://www.markus-gattol.name/ws/bash.html
| url-status = live
| website = markus-gattol.name
}}
}}
</ref>
It also supports the execution of commands from files, known as [[shell script]]s, facilitating [[automation]].
 
The Bash command [[syntax (programming languages)|syntax]] is a [[superset]] of the Bourne shell, `{{mono|sh}}`, command syntax, from which all basic features of the (Bash) [[formal language|syntax]] were copied.
As a result, Bash can execute the vast majority of Bourne shell scripts without modification.
Some other ideas were borrowed from the [[C shell]], `{{mono|csh}}`, and its successor `{{mono|tcsh}}`, and the [[Korn Shell]], `{{mono|ksh}}`.
It is available on nearly all modern operating systems, making it a versatile tool in various computing environments.
 
== Definitions <span class="anchor" id="Definitions"></span> ==
 
=== ASCII, strings and numbers <span class="anchor" id="ASCII"></span> <span class="anchor" id="strings"></span> <span class="anchor" id="numbers"></span> ===
 
<!-- Important concepts:
[x] Characters
[x] Human/computer communitcation
[x] Standardization
[x] Character encoding
[x] Control characters
[ ] Information
-->
{{Blockquote
| The input language to the shell shall be first recognized at the character level.<ref>
{{Cite web
| access-date = 25 August 2025
| publisher = [[The Open Group]]
| title = POSIX 1003.1-2024, 2.10.1 Shell Grammar Lexical Conventions
| url = https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_10_01
| work = The Open Group Base Specifications Issue 8, IEEE Std 1003.1-2024
}}
</ref>
| author = POSIX 1003.1-2024, 2.10.1 Shell Grammar Lexical Conventions
}}
 
All input and output at the [[Command-line interface |command line]] is communicated using printable, human-language characters, such as the letter "a" or the number "1."<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Mozilla Corporation]]
| title = MDN Glossary of web terms: character
| url = https://developer.mozilla.org/en-US/docs/Glossary/Character
| website = mozilla.org
| date = 11 July 2025
}}
</ref>
One of the earliest devised and most widespread ways of encoding these characters in a consistent manner which computers could understand was a [[Standardization |standard]] called [[ASCII]].<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = ASCII
| url = https://www.britannica.com/topic/ASCII
| website = britannica.com
}}
</ref>
ASCII systematically encodes human readable text into and out of [[Binary number |binary]] code which can be read by computers.<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = binary code
| url = https://www.britannica.com/technology/binary-code
| website = britannica.com
}}
</ref>
Today, all modern [[terminal emulators]] are capable of understanding all 95 English language printable characters and numerous [[control characters]] from the 128 code-point ASCII standard for [[character encoding]].<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = code
| url = https://www.britannica.com/topic/code-communications
| website = britannica.com
}}
</ref>
Control characters most commonly seen during a shell session are "newline," "tab," "space" and "null."<ref>
{{Cite web
| access-date = 25 August 2025
| publisher = [[The Open Group]]
| title = POSIX 1003.1-2024, 6. Character Set
| url = https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap06.html#tag_06
| work = The Open Group Base Specifications Issue 8, IEEE Std 1003.1-2024
}}
</ref>
 
:<syntaxhighlight lang="console">
$ printf '<newline>: <%b>\n' $'\n'
<newline>: <
>
$ printf '<tab>: <%b>\n' $'\t'
<tab>: < >
$ printf '<space>: <%s>\n' " "
<space>: < >
$ printf '<NUL>: <%b>\n' $'\0'
<NUL>: <>
</syntaxhighlight>
 
<!-- Important concepts:
[x] String
[x] Filenames
-->
Any series of characters is called a "[[String (computer science) |string]]," or sometimes a "[[string literal]]."
In Unix-like operating systems, all characters, printable and non-printing, except for a few such as the [[null character]] and forward slash {{char|/}}, can be used in naming [[Filenames |files]].
In Unix-like operating systems, all strings are case-sensitive.<ref>
{{Cite book
| access-date = 16 August 2025
| date = 2008
| first = Randal
| isbn = 978-0-470-18301-4
| last = Michael
| page = 3
| publisher = [[Wiley (publisher) |Wiley Publishing, Inc.]], Indianapolis, Indiana
| quote = UNIX is case sensitive. Because UNIX is case sensitive, our shell scripts are also case sensitive.
| title = Mastering Unix Shell Scripting, 2e
| url = https://books.google.com/books?id=uI7C2BDF6F0C
}}
</ref>
 
<!-- Important concepts:
[x] Zero-based numbering
[]
-->
In everyday life, people usually begin counting some group of items from the number one: 1, 2, 3 apples.
In computer science it is customary to do as the computers do and begin counting the first item from the number zero: 0, 1, 2 oranges, for a total of 3 oranges.
 
Among computer languages, [[Zero-based numbering#Computer programming |zero-based numbering]] was used early on in [[BCPL]] in 1967.<ref>
{{Cite web
| access-date = 25 August 2025
| archive-date = 20 January 2013
| archive-url = https://web.archive.org/web/20130120134910/http://cm.bell-labs.com/cm/cs/who/dmr/bcpl.pdf
| author = Martin Richards
| date = 21 July 1967
| page = 23
| publisher = Massachusetts Institute of Technology
| quote = The minimum subscript value is always zero.
| title = The BCPL Reference Manual, 7.6 Vector Definitions
| url = http://cm.bell-labs.com/cm/cs/who/dmr/bcpl.pdf
| url-status = dead
| website = bell-labs.com
}}
</ref>
BCPL is a precursor of the [[C (programming language) |C programming language]], in which Bash is written.
In [[C++]], a descendant of C, it's also true that "arrays start indexing from element 0."<ref>
{{Cite book
| access-date = 25 August 2025
| author = Graham M. Seed
| date = 11 May 2001
| page = 195
| quote = C++ arrays start indexing from element 0.
| publisher = [[Springer Science+Business Media]]
| title = An Introduction to Object-Oriented Programming in C++, 7.4 Array Indexing
| url = https://books.google.com/books?id=_lqj98AsnGAC&q=zeroth+element&pg=PA195
| isbn = 978-1-85233-450-5
}}
</ref>
The array's name and index number are a synonym for the data's ___location in memory.<ref>
{{Cite book
| access-date = 25 August 2025
| author = Graham M. Seed
| date = 11 May 2001
| page = 210
| publisher = [[Springer Science+Business Media]]
| quote = The name of an array is a synonym for the memory ___location of the array.
| title = An Introduction to Object-Oriented Programming in C++, 7.12.1 One-Dimensional Arrays
| url = https://books.google.com/books?id=_lqj98AsnGAC&q=zeroth+element&pg=PA210
| isbn = 978-1-85233-450-5
}}
</ref>
In 1982, [[Edsger W. Dijkstra |E.W. Dijkstra]] advocated for zero-based numbering of array indices in his paper, "Why numbering should start at zero."
As he notes, 'an element's subscript equals the number of elements preceding it in the sequence.<ref>
{{Cite web
| access-date = 25 August 2025
| author = [[Edsger W. Dijkstra]]
| page = 2
| publisher = [[University of Texas at Austin]]
| quote = So let us let our ordinals start at zero: an element's ordinal (subscript) equals the number of elements preceding it in the sequence.
| title = Why numbering should start at zero
| url = https://www.cs.utexas.edu/~EWD/transcriptions/EWD08xx/EWD831.html
| website = utexas.edu
}}
</ref>
 
=== CLI and GUI <span class="anchor" id="CLI and GUI"></span> ===
 
{{Main
| Computer terminal
| VT100
| Command-line interface
| Terminal emulator
| Graphical user interface
}}
 
<!-- Important concepts:
[x] Origin of CLI paradigm
[x] Origin of terminal emulators
[x] GUI
-->
Long after the first Analytical Engine, in the mid-1960's one of the primary ways for humans and computers to interact in real time was at a keyboard with a [[teleprinter]]: only display of textual characters was possible.<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = Analytical Engine
| url = https://www.britannica.com/technology/Analytical-Engine
| website = britainnica.com
}}
</ref>
In the 1970s, after [[computer monitor]]s were developed yet before display of graphics was available, these interfaces were integrated and were known as hardware video [[Computer terminal |terminals]].
Their interaction [[paradigm]] is the basis of what we consider the [[command-line interface]] (CLI).
 
When computers gained the ability to draw graphics on a monitor, [[graphical user interface]]s (GUI's) were designed.<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = graphical user interface
| url = https://www.britannica.com/technology/graphical-user-interface
| website = britannica.com
}}
</ref>
[[Terminal emulator]]s are GUI software programs which create a visual representation of these earlier hardware [[computer terminal]]s.
Today, when a human user initiates a login session, that procedure usually occurs via some [[graphical user interface]].
 
=== Control+key combinations <span class="anchor" id="GNU Readline"></span> ===
 
<!-- Important concepts:
[x] Keypress combinations
[x] Terminal emulator as separate from shell
-->
This functionality is provided by a program called [[GNU Readline]] and is available in interactive mode only.
Certain keypress combinations allow a user to operate Bash to use tab completion and to search the command history.
 
* {{Keypress|Tab}} - Activate tab completion
* {{Keypress|up}} - Scroll up (ie, backward) in the command history
* {{Keypress|down}} - Scroll down (ie, forward) in the command history
* {{Keypress|Ctrl|r}} - Search the command history
 
Some keypress combinations also allow a user to operate the terminal emulator in order to move the cursor within the terminal window and to control the emulator program.
By default, these keypress combinations in Bash mirror those of the [[Emacs]] text editing software.<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = GNU Bash Manual: 8.2.1 Readline Bare Essentials
| url = https://www.gnu.org/software/bash/manual/html_node/Readline-Bare-Essentials.html
| website = [[Free Software Foundation, Inc.]]
}}
</ref>
Default keybindings for control codes include:
 
* {{Keypress|Ctrl|right}} - Move the cursor one word to the right
* {{Keypress|Ctrl|left}} - Move the cursor one word to the left
* {{Keypress|Ctrl|a}} - Move the cursor to the beginning of the current commandline
* {{Keypress|Ctrl|c}} - Cancels the current command and presents a new prompt
* {{Keypress|Ctrl|d}} - Closes the current Bash instance, possibly also closing the terminal-emulator
* {{Keypress|Ctrl|e}} - Move the cursor to the end of the current commandline
* {{Keypress|Ctrl|q}} - Wake the terminal; buffered keypresses are then processed
* {{Keypress|Ctrl|s}} - Put the terminal to sleep
* {{Keypress|Ctrl|w}} - Remove one word to the left of the cursor
* {{Keypress|Ctrl|z}} - Stop a foregrounded process
 
[[Vi (text editor)]] keybindings are also available and can be enabled by running {{Code|set -o vi|bash}}.<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = GNU Bash Manual: 8.5 Readline vi mode
| url = https://www.gnu.org/software/bash/manual/html_node/Readline-vi-Mode.html
| website = [[Free Software Foundation, Inc.]]
}}</ref><ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 2 March 2021
| archive-url = https://web.archive.org/web/20210302213519/http://www.hypexr.org/bash_tutorial.php#emacs
| date = 5 October 2012
| first = Scott
| last = Rippee
| title = Getting started with BASH: A Bash Tutorial
| url = https://www.hypexr.org/bash_tutorial.php#emacs
| website = hypexr.org
}}</ref>
 
| website = {{url|http://www.gnu.org/software/bash/}}
=== Syntax <span class="anchor" id="Syntax"></span><span class="anchor" id="Tokens"></span><span class="anchor" id="Metacharacters"></span><span class="anchor" id="Operators"></span><span class="anchor" id="Words"></span><span class="anchor" id="Names"></span> ===
 
<!-- Important concepts:
[] stream of characters
[] delineate full commandlines (newline, semi-colon)
[] division into commands and parts of commands (optargs)
[] uses metacharacters
-->
<syntaxhighlight lang = text>
"Tokens"
\_ "Blanks"
\_ "Operators" (Ops)
\_ "Control Ops"
\_ "Redirection Ops"
\_ "Words"
\_ "Reserved Words"
\_ "Names"
</syntaxhighlight>
 
{{Blockquote
| syn{{dot}}tax '''1 a :''' the way in which linguistic elements (such as words) are put together to form constituents (such as phrases or clauses) '''b :''' the part of grammar dealing with this<ref>
{{Cite web
| access-date = 25 August 2025
| title = syntax, noun
| url = https://www.merriam-webster.com/dictionary/syntax
| website = merriam-webster.com
}}
</ref>
| author = Merriam-Webster Dictionary
}}
 
 
'''Bash''' is a [[Unix shell]] written by [[Brian Fox (computer programmer)|Brian Fox]] for the [[GNU Project]] as a [[free software]] replacement for the [[Bourne shell]] (sh).<ref name="GNUBSD">
When Bash reads a ''full commandline,'' the complete string is broken down according to a certain set of rules into individual units called ''"tokens."''
{{Cite newsgroup
"Tokens" are identified using, and separated from each other using ''"metacharacters."'' (As of version 5.3:)
| title = GNU + BSD = ?
 
| author = [[Richard Stallman]] (forwarded with comments by Chet Ramey)
* The ten ''"metacharacters:"''
| date = February 10, 1988
 
| newsgroup = comp.unix.questions
: {{Pre |‘space’ ‘tab’ ‘newline’ ‘|’ ‘&’ ‘;’ ‘(’ ‘)’ ‘<’ ‘>’}}
| id =
 
| url = http://groups.google.com/group/comp.unix.questions/msg/e44ad620f76be7c9?hl=en
''"Blanks"'' are composed entirely of unquoted metacharacters, ''"operators"'' each contain at least one unquoted metacharacter and ''"words"'' may not include any unquoted metacharacters.
| accessdate = Mar 22, 2011
 
| quote = For a year and a half, the GNU shell was "just about done". The author made repeated promises to deliver what he had done, and never kept them. Finally I could no longer believe he would ever deliver anything. So Foundation staff member Brian Fox is now implementing an imitation of the Bourne shell.
In practice, Bash breaks down ''full command strings'' into tokens or groups of tokens that ''do'' contain metacharacters and tokens or groups of tokens that do ''not'' contain any metacharacters -- called ''"words."''
From there it further breaks ''words'' down into more specific, meaningful pieces like command names, variable assignment statements, etc.
 
* The two ''"blanks"''
 
: {{Pre |‘space’ ‘tab’}}
 
* ''"Operators"''
 
:* Eight of the twelve ''"control operators:"''
 
:: <syntaxhighlight lang = text>
‘newline’ ‘;’ ‘&’ ‘|’ ‘||’ ‘&&’ ‘(’ ‘)’ ...
</syntaxhighlight>
 
:* Five of the fourteen ''"redirection operators:"''
 
:: <syntaxhighlight lang = text>
‘<’ ‘>’ ‘&>’ ‘<<’ ‘<<<’ ...
</syntaxhighlight>
 
A ''"word"'' is a sequence of (non-meta-) characters treated as a single unit by the shell.
A ''"reserved word"'' is a kind of a ''"word"'' that has a special meaning to the shell.<ref>
{{Cite web
| access-date = 18 August 2025
| title = Bash Reference Manual, D.2 Index of Shell Reserved Words
| url = https://www.gnu.org/software/bash/manual/bash.html#Reserved-Word-Index
}}
</ref>
A ''"name"'' is a kind of a ''"word,"'' separate from ''reserved words'', which consists solely of letters, underscores and numbers; which begins with either a letter or an underscore; which, however, may not begin with a number.
''"Names,"'' also called ''"identifiers,"'' may be used for naming variables and functions.
 
* ''"Words"''
 
:* Sixteen of the twenty-two ''"reserved words,"'' which may be characters or words:
 
:: <syntaxhighlight lang = bash>
‘!’ ‘[[’ ‘{’ ‘]]’ ‘}’ case in esac for do done if then elif else fi ...
</syntaxhighlight>
 
:* ''"Names"'' may contain only these characters (in the English language):
 
:: <syntaxhighlight lang = text>
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 ‘_’
</syntaxhighlight>
 
In the following example of a full command string, ''metacharacters'' have an comma placed above them, {{Code| ,}}, ''reserved words'' have an carrat placed beneath them, {{Code| ^}}, and other ''tokens'' have a backtick placed also beneath them, {{Code| `}}.
 
: <syntaxhighlight lang = console>
$ #, , , ,, , ,, ,
$ if echo foo; then bar=abc; fi
$ # ^^ ```` ``` ^^^^ ``````` ^^
</syntaxhighlight>
 
=== Subshells <span class="anchor" id="Subshells"></span> ===
 
<!-- Important concepts:
[x] Subshells
[x] Process and environment info, ie, parent/child, exact copy, etc
-->
 
A "subshell" is an additional instance of the shell which has been intitialized by a current instance of the shell.
When a "parent" shell creates a subshell, or a "child" shell, an exact copy of the parent's environment information is re-created and becomes the environment of the subshell.
 
In Bash, in non-arithmetic contexts, one can force the use of a subshell by enclosing a full command string in ''single parentheses''.
 
: <syntaxhighlight lang = console>
$ echo foo
foo
$ ( echo foo )
foo
$
</syntaxhighlight>
 
For this simple case, the preceding two commands are equivalent, however, use of subshells can have certain unexpected side effects.
There are numerous different forms of syntax which can cause the initialization of a subshell.
 
=== Expansion <span class="anchor" id="Expansion"></span> ===
 
<!-- Important concepts:
[]
-->
"Expansion" is a crucial concept in Unix-like shells. See [[String interpolation]].
 
"Shell expansion is a process where the shell interprets and replaces certain expressions before executing a command."
- https://www.spsanderson.com/steveondata/posts/2024-10-18/
 
"Variable expansions are substituted textually into the command, and thus variables which contain nothing simply disappear from the syntax, and variables which contain spaces turn into multiple tokens. This can lead to syntax errors or bugs."
- [[Batch file]]
 
"String interpolation (...or variable expansion) is the process of evaluating a [[string literal]] containing one or more [[placeholders]], yielding a result in which the placeholders are replaced with their corresponding values. It is a form of simple [[Template processor|template processing]] or, in formal terms, a logic [[Substitution (logic)|substitution]] interpretation. The placeholder may be a variable name, or in some languages an arbitrary expression, in either case evaluated in the current [[Scope (computer science)|context]].
- [[String interpolation]]
 
Expansion vs Substitution
- https://unix.stackexchange.com/questions/125007/difference-between-expansion-and-substitution-in-shell-scripting-terminology
* An ''expansion'' is extracting the value of an identifier.
* A ''substitution'' creates a value as the result of an explicit input/output operation.
 
=== Variables and arrays <span class="anchor" id="Data structures"></span><span class="anchor" id="Variables"></span><span class="anchor" id="Arrays"></span> ===
 
<!-- Important concepts:
[x] Data structure
[ ] Expansion
[ ] Variables
[x] Kinds of variables
[x] Naming conventions
[?] Positional parameters
[?] Special parameters
[x] Environment variables
[x] Scripting variables
[x] Arrays
-->
For data structures Bash offers variables and arrays, and though there are numerous kinds of each of these available, the data structures are relatively simple compared to other languages like [[C (programming language) |C]] or [[Java (programming language) |Java]].<ref>{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| quote = Some data structures are useful for simple general problems, such as retrieving data that has been stored with a specific identifier. ... The simplest data structure is the one-dimensional (linear) array, in which stored elements are numbered with consecutive integers and contents are accessed by these numbers.
| title = data structure
| url = https://www.britannica.com/technology/central-processing-unit
| website = britannica.com
}}</ref>
All data is stored in memory as a string.
 
'''Syntax common among data structures in Bash:'''
Beginnning a word with a dollar character signifies that the word is the name of a variable or array.
Surrounding the dollar / variable name syntax in double quotes is always advised.
This practice sheilds the value(s) held by the parameter(s) from unwanted side effects.
 
Wrapping the variable name also in curly brackets is recommended for readablility and for consistency between variables and arrays.
When writing variables, curly braces are optional and square brackets would be a syntax error. The parameter names are always on the left side of the equals sign and values are always on the left.
 
* ''Variable''
** Assignment: <CODE>foo=bar</CODE>
** Expansion: {{Code| "${foo}"| bash}} "Expands to the value assigned to the variable" foo.<ref name =multics_ec/>
 
Arrays have in addition a set of square brackets placed at the end of the variable name and inside the curly braces.
When writing arrays, curly braces and square brackets are required.
 
* ''Array''
** Assignment: <CODE>quux=( a b c )</CODE>
** Expansion: {{Code| "${quux[@]}"| bash}} or {{Code| "${quux[*]}"| bash}} or {{Code| "${quux[1]}"| bash}}
 
Each kind of parameter is distinguished by a specific [[Naming convention (programming) |naming convention]].<ref>
{{Cite web
| access-date = 14 August 2025
| publisher = [[GNU Project]]
| quote = A parameter is an entity that stores values. It can be a name, a number, or one of the special characters listed below. ... A variable has a value and zero or more attributes.
| title = Bash Reference Manual, 3.4 Shell Parameters
| url = https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameters
| website = [[Free Software Foundation, Inc.]]
}}</ref>
 
<!-- Q: What _are_ positional parameters, anyway? -->
* '''Variables:''' Data structures which hold just one value
** Positional parameters: signified by integers.<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[GNU Project]]
| title = Bash reference manual, 3.4.1 Positional Parameters
| url = https://www.gnu.org/software/bash/manual/bash.html#Positional-Parameters
| website = [[Free Software Foundation, Inc.]]
}}</ref>
*** "$1" "$2" "$3" ... "${10}" "${11}" "${12}" - "The parentheses are required when there are two or more digits."<ref name = multics_ec>
{{Cite web
| access-date = 8 August 2025
| date = 23 March 1984
| publisher = [[Massachusetts Institute of Technology]] and [[Honeywell]] Information Systems, Inc.
| title = exec_com, ec
| url = https://web.mit.edu/multics-history/source/Multics/doc/info_segments/exec_com.info
| website = mit.edu
}}</ref><ref>
{{Cite web
| access-date = 18 August 2025
| publisher = [[Case Western Reserve University]]
| title = Bash Reference Manual, 3.4.1 Positional Parameters
| url = https://tiswww.case.edu/php/chet/bash/bashref.html#Positional-Parameters
| website = case.edu
}}</ref>
** Special parameters: signified by punctuation characters<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[GNU Project]]
| title = Bash reference manual, 3.4.2 Special Parameters
| url = https://www.gnu.org/software/bash/manual/bash.html#Special-Parameters
| website = [[Free Software Foundation, Inc.]]
}}</ref><ref>
{{Cite web
| access-date = 18 August 2025
| publisher = [[Case Western Reserve University]]
| title = Bash Reference Manual, 3.4.2 Special Parameters
| url = https://tiswww.case.edu/php/chet/bash/bashref.html#Special-Parameters
| website = case.edu
}}</ref>
*** "$@" - Expands to a list of the first through last positional parameters, "individually requoted, separated by spaces."<ref name =multics_ec/>
*** "$$" "$?" "$-"
** Environment variables: signified by all capital letters
*** UNIX variables
**** LESS_SIGUSR1
*** Shell variables
**** Bourne shell variables<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[GNU Project]]
| title = Bash reference manual, 5.1 Bourne Shell Variables
| url = https://www.gnu.org/software/bash/manual/bash.html#Bourne-Shell-Variables
| website = [[Free Software Foundation, Inc.]]
}}</ref>
***** "$HOME"
**** Bash variables<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[GNU Project]]
| title = Bash reference manual, 5.2 Bash Variables
| url = https://www.gnu.org/software/bash/manual/bash.html#Bash-Variables
| website = [[Free Software Foundation, Inc.]]
}}</ref>
** Scripting variables: signified by all lower case letters or by CamelCase
 
* '''Arrays:''' Data structures which hold multiple values<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[GNU Project]]
| title = Bash reference manual, 6.7 Arrays
| url = https://www.gnu.org/software/bash/manual/bash.html#Arrays
| website = [[Free Software Foundation, Inc.]]
}}</ref><ref>
{{Cite web
| access-date = 15 August 2025
| date = 6 November 2016
| title = Thirteen Incorrect Ways and Two Awkward Ways to Use Arrays
| url = https://www.oilshell.org/blog/2016/11/06.html
| website = oilshell.org
}}</ref>
** Indexed arrays<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = integer
| url = https://www.britannica.com/science/integer
| website = britannica.com
}}</ref>
** Associative arrays
 
In this article, examples of [[Variable (computer science) |variables]] from this section include "${foo}", PID, PWD, EUID, $$, "${quux}" and "${zork}".<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Merriam-Webster's Collegiate Dictionary]]
| title = parameter (noun)
| url = https://www.merriam-webster.com/dictionary/parameter
| website = merriam-webster.com
}}</ref>
 
=== Processes <span class="anchor" id="Processes"></span> ===
 
{{Main
| Process (computing)
| Attribute (computing)
}}
 
<!-- Important concepts:
[x] Kernel
[x] Process
[x] Attributes
[x] Identifying attributes
[x] Effective identifiers
[x] Working directory
-->
Each [[operating system]] (OS) has at its core a program called the [[Kernel (operating system) |kernel]] which runs commands.<ref name = Brit_control-unit>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = control unit
| url = https://www.britannica.com/technology/control-unit
| website = britannica.com
}}</ref>
The kernel, or "control unit," manages a machine's [[central processing unit]] (CPU).<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = central processing unit
| url = https://www.britannica.com/technology/central-processing-unit
| website = britannica.com
}}</ref>
Any program running on a computer including the kernel can be described as something called a "process."<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = computer program
| url = https://www.britannica.com/technology/computer-program
| website = britannica.com
}}</ref>
Processes can be identified and described as having a certain list of "attributes" such as {{mono|PID}}, {{mono|PWD}} and {{mono|EUID}}.
 
A [[process identifier]] ''attribute'', denoted in Bash by the variable dollar {{Code| $$}}, is a unique integer between 300 and approximately <math>2^{24}</math>, depending on the OS.
Most processes also have a current [[working directory]] (CWD) ''attribute'' which is denoted in Bash by the variable {{Code| $PWD}} and discoverable with the shell builtin {{mono|pwd}} (short for "print working directory").
All [[Process (computing) |processes]] have attributes which identify their user and group ID's, {{Code| $UID}} and {{Code| $GID}}, and their ''"effective"'' user and group ID's, {{Code| $EUID}} and {{Code| $EGID}}.
Processes can have "effective" owner and group identifiers, but files may not.
 
:<syntaxhighlight lang="console">
$ ps -o pid,uid,euid,gid,egid,cmd=Command | grep -e [b]ash -e [P]ID
PID USER UID EUID GID EGID Command
3237 liveuser 1000 1000 1000 1000 bash
$ declare -p PWD
declare -x PWD="/home/liveuser"
$
</syntaxhighlight>
 
=== Files and permissions <span class="anchor" id="Files and permissions"></span><span class="anchor" id="Files"></span><span class="anchor" id="Permissions"></span> ===
 
{{Main
| File system
| Unix file types
| File-system permissions
}}
 
<!-- This subsection is messy -->
<!-- Important concepts:
[x] "Everything is a file"
[x] Filesystem permissions
[x] The kernel allows access based on permissions
[?] Mode
[?] umask
-->
In Unix-like operating systems, all objects locatable on the [[file system]] are considered to be "files."<ref name = tldp_3.1.1>
{{Cite web
| access-date = 13 August 2025
| quote = A simple description of the UNIX system, also applicable to Linux, is this: "On a UNIX system, everything is a file; if something is not a file, it is a process."
| title = Introduction to Linux, Ch. 3 About files and the filesystem, 3.1. General overview of the Linux file system, 3.1.1 Files
| url = https://tldp.org/LDP/intro-linux/html/sect_03_02.html#sect_03_02_02
| website = [[Linux Documentation Project]]
}}</ref>{{efn
| This description does not apply to [[Microsoft Windows |Windows]]-based operating systems.
}}
This term, "files," is an umbrella [[jargon]] which includes [[text file]]s, [[binary file]]s, [[Directory (computing) |directories]], [[Device file |device files]] which are used to represent [[computer hardware]], [[symbolic links]] and [[hard link]]s between files: most anything locatable on a file-system.
 
All "[[Unix file types |files]]" have a set of [[file-system permissions |file-system permission]] attributes, such as owner and group memberships, which control how [[Process (computing) |processes]] may interact with the file.
These permissions are user configurable so they're considered a kind of [[discretionary access control]] (DAC).
File permissions describe whether each of "owner," "group" or "other," may have "read," "write" or "execute" access.
When a user, via some process, requests access to a file, the kernel looks at the process's and files's identifying attributes, and at the file's permissions.
From there, the kernel determines whether and how any particular user process may interact with any particular file.
 
:<syntaxhighlight lang="console">
$ ls -l ~/.bashrc
-rw--r--r--. 1 liveuser liveuser 7597 Aug 11 20:01 /home/liveuser/.bashrc
$
</syntaxhighlight>
 
In Unix-like OS's, a written representation of a file's [[discretionary access control]] (DAC) permissions is called a "mode."<ref>
{{Man
|1|chmod|ManKier
}}</ref>
Shell builtin {{Code| umask}} allows the user to define a default set of DAC permissions for all files created thereafter.<ref name = tldp_3.4.2.3>
{{Cite web
| access-date = 13 August 2025
| title = Introduction to Linux, Ch. 3 About files and the filesystem, 3.4 File security, 3.4.2.3. The file mask
| url = https://tldp.org/LDP/intro-linux/html/sect_03_04.html
| website = [[Linux Documentation Project]]
}}</ref>
 
{{Quote
| The standard file permission is determined by the ''mask'' for new file creation. The value of this mask can be displayed using the {{Code| umask| bash}} command. Instead of adding the symbolic values to each other, as with {{Code| chmod| bash}}, for calculating the permission on a new file they need to be subtracted from the total possible access rights.
| style =
}}
 
=== Paths <span class="anchor" id="Paths"></span> ===
 
{{Main |Path (computing)
| Hierarchical file system
}}
 
<!-- Important concepts:
[x] Absolute paths
[x] Relative paths
[x] File anchor: './'
-->
In Unix-like OS's, files, hardlinks, device nodes, etc., (i.e., "files") are sorted into [[Directory (computing) |directories]] that form a hierarchical file structure which is nested in a "parent" and "child" manner.
The base of the hierarchy is called the "root directory" which is denoted by one forward slash: {{char|/}}.
 
On the command line, a file can be identified using its full filename or an abbreviated filename.<ref name = tldp_3.2.2>
{{Cite web
| access-date = 13 August 2025
| title = Introduction to Linux, Ch. 3 About files and the filesystem, 3.2 Orientation in the filesystem, 3.2.2 Absolute and relative paths
| url = https://tldp.org/LDP/intro-linux/html/sect_03_02.html#sect_03_02_02
| website = [[Linux Documentation Project]]
}}</ref>
When the kernel searches for a directory, the starting point is the leftmost character of directory name.
For full filenames, or "absolute paths," the leftmost directory is known positively: it's the filesystem root directory, {{code|/}}.
For abbreviated filenames, or "relative paths," as shorthand on the commandline the current [[working directory]] (CWD) can be referred to as {{code|.}}, and its parent directory as {{Code| ..}}.{{efn|The shell builtin {{code|.}}, synonymous with the {{Code| source}} builtin, is something else.}}
If a shell process attempts to locate any filename that begins with the string {{Code| ./}}, it will only search in the current working directory of that process.
 
:<syntaxhighlight lang="console">
$ realpath -e . ..
/home/liveuser
/home
$
</syntaxhighlight>
 
The {{Code| $PATH| bash}} variable will be discussed in detail in the section, {{Section link|| PATH and system commands}}.
 
=== Execution <span class="anchor" id="Execution"></span> ===
 
{{Main
| Execution (computing)
}}
 
<!-- Important concepts:
[x] Execution / to execute a command
[x] An executable
[x] Bash reads one line at a time
[x] Line continuation
[x] Command position
[ ] A single logical construct is parsed as a single unit
-->
"Execution" of a given program occurs when a user (or some other program) asks the operating system to act upon the instructions contained in the given program.
 
By default, Bash reads user code one line at a time, interprets any newline or semi-colon character {{code|;}} as the end of the current command, and executes commands in sequence.
If an interactive command extends beyond the width of the terminal emulator, it's usually possible to keep typing and the command will wrap around.
To extend a command beyond a newline onto an additional line, it's necessary that the final character of the first line be an unescaped backslash, {{code|\}}, which signals "line continuation."
Bash always finishes parsing and executing one full commandline before moving on to and beginning with the parsing of the next commandline.
 
:<syntaxhighlight lang="console">
$ foo=aa bar=bb quux=cc zork=dd; set -o xtrace
$ : "${foo}"; : "${bar}"
+ : aa
+ : bb
$ : "${quux}" \
> : "${zork}"
+ : cc : dd
$
</syntaxhighlight>
 
The first word of a commandline is known as the "command position."
Under UNIX coventionality, the first word of the commandline is always some kind of a command, and the rest of the words in the commandline string are either options for the command, arguments for the options, or some kind of input upon which the command will operate.
"Options" are also called "flags," "switches," or, more formally, "operators."
When Bash attempts to locate a command for execution, the directories it searches are those listed in the {{Code| $PATH}} variable and the current working directory.<ref name = tldp_3.2.1>
{{Cite web
| access-date = 13 August 2025
| quote = The PATH environment variable ... lists those directories in the system where executable files can be found, and thus saves the user a lot of typing and memorizing locations of commands.
| title = Introduction to Linux, Ch. 3 About files and the filesystem, 3.2 Orientation in the filesystem, 3.2.1 The path
| url = https://tldp.org/LDP/intro-linux/html/sect_03_02.html#sect_03_02_01
| website = [[Linux Documentation Project]]
}}</ref>
 
:<syntaxhighlight lang="console">
$ # [COMMAND POSITION] [OPTION] [ARGUMENTS]
$ # ,--^ ,------------^ ,----^
$ declare -p USER BASH_VERSION
declare -x USER="liveuser"
declare -- BASH_VERSION="5.2.37(1)-release"
$
</syntaxhighlight>
 
=== Users and PS1 <span class="anchor" id="Users and PS1"></span><span class="anchor" id="Users"></span><span class="anchor" id="PS1"></span> ===
 
<!-- Important concepts:
[x] Human vs programmatic users
[x] Privileged vs regular users
[x] Root and the kernel are privileged
[x] PS1, re visual examples
-->
A [[User (computing) |user account]] can be created for either a human or a programmatic user.
In Unix-like OS's, there are two kinds of users: "privileged" and "regular."
A privileged user, such as "root" or the operating system [[Kernel (operating system) |kernel]], is allowed to do anything whatsoever on the machine.
Unprivileged users are limited in various ways.
 
When an interactive shell session waits for user [[Input/output |input]], often within a [[terminal emulator]] connected to a [[peripheral]] keyboard, by default it prints a particular string of characters to the screen.<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = peripheral device
| url = https://www.britannica.com/technology/input-output-device
| website = britannica.com
}}</ref>
In Bash, the [[Value (computer science) |value]] of this waiting-string is held in the shell [[Variable (computer science) |variable]] {{Code| $PS1}}.
For regular users a common default value for {{Code| $PS1}} is the dollar character, {{char|$}}.{{efn|not to be confused with the shell variable {{Code| $$}}}}
For the [[superuser]] a common default value is hashtag ({{char|#}})
 
:<syntaxhighlight lang="console">
$ sudo --login --user root
[sudo] password for liveuser:
# vim /home/liveuser/names.txt
# exit
$ grep -e bob ./names.txt
grep: ./names.txt: Permission denied
</syntaxhighlight>
 
== Modes <span class="anchor" id="Modes"></span> ==
 
=== Programming paradigm <span class="anchor" id="Programming paradigm"></span> ===
 
<!-- Important concepts:
[x] Shell as a "programming language"
[?] Bash/shell is an imperative language
[ ] Bash/shell was not intended to be a functional language
-->
{{Blockquote
|Although most users think of the shell as an interactive command interpreter, it is really a programming language in which each statement runs a command. Because it must satisfy both the interactive and programming aspects of command execution, it is a strange language, shaped as much by history as by design.<ref>
{{Cite book
| access-date =
| author-first1 = Brian W.
| author-last1 = Kernighan
| author-link1 = Brian Kernighan
| author-first2 = Rob
| author-last2 = Pike
| author-link2 = Rob Pike
| date = 1984
| isbn = 0-13-937699-2
| ___location = Englewood Cliffs
| publisher = [[Prentice-Hall]]
| title = The UNIX Programming Environment
| url = https://archive.org/details/unixprogramminge0000kern
| url-access = registration
}}</ref>
| [[Brian W. Kernighan]] & [[Rob Pike]]
| style =
}}
 
 
Bash was written in C.<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = C
| url = https://www.britannica.com/technology/C-computer-programming-language
| website = britannica.com
}}</ref>
A modular style can be approximated through good style and careful design.<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Dartmouth University]]
| title = Modular data structures in C
| url = https://www.cs.dartmouth.edu/~cs50/Lectures/modules/
| website = dartmouth.edu
}}</ref>
It is often used in an [[Imperative programming |imperative]] or [[Procedural programming |procedural]] style.<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = computer programming language
| url = https://www.britannica.com/technology/computer-programming-language
| website = britannica.com
}}</ref>
<!-- https://www.cs.dartmouth.edu/~cs50/Lectures/modules/ -->
 
=== Interactive and non-interactive modes <span class="anchor" id="Interactive and non-interactive modes"></span><span class="anchor" id="Interactive mode"></span><span class="anchor" id="Non-interactive mode"></span> ===
 
<!-- Important concepts:
[x] Terminal emulator
[x] Shell script
-->
As a [[Command-line interface|command processor]], Bash can operate in two modes: interactive or non-interactive.
In [[Human–computer interaction|interactive]] mode, commands are usually read from a [[terminal emulator]].
In non-interactive mode, which facilitates [[automation]], commands are usually read from named files known today as [[shell script]]s.
When executed as a standalone command at the [[command-line interface]] (CLI), by default Bash opens a new shell in interactive mode.
 
=== Scripts <span class="anchor" id="Scripts"></span> ===
 
<!-- Important concepts:
[x] Interpreter
[x] Computer program
[x] Executable
[x] Hash-bang
[x] Execute-bit
-->
[[Shell scripts]] are text files that contain [[Programming language |code]], often [[Command (computing) |commands]], intended to be read and acted upon by some particular [[Interpreter (computing) |interpreter]] in a [[Batch processing |batch process]] in a ''non-interactive mode'' and without any further user interaction.
Interpreted scripts are [[Computer program |programs]] that do not require their [[source code]] to be [[Compiler |compiled]]: all of the relevant source code is contained within the script.
There are many programs which can serve as an script interpreter: [[Perl]],<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = Perl
| url = https://www.britannica.com/technology/Perl
| website = britannica.com
}}</ref>
[[Ruby (programming language)|Ruby]], [[Python (programming language) |Python]],<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = Python
| url = https://www.britannica.com/technology/Python-computer-language
| website = britannica.com
}}</ref>
[[AWK]], etc.
Interpreted scripts are most often written for Unix shells.
 
The first two characters of the first line of any (executable) shell script begins with a something called a [[Shebang (Unix) |hash-bang]]: literally the characters hashtag ({{char|#}}) and bang ({{char|!}}) side by side.
 
:<syntaxhighlight lang = console>
$ cat ./example.sh
#! /bin/env bash
echo foo
exit
 
$
</syntaxhighlight>
 
If a script is intended to be run by a user as a stand-alone program on the commandline, then it is referred to as an ''"executable."''
By convention, the filenames of [[Execution (computing) |executable]] unix shell scripts are identified the suffix {{mono|.sh}}.
The "execute" bit can be enabled on a shell script with the utility {{mono|chmod}}:
 
:<syntaxhighlight lang = console>
$ ls -l ./example.sh
-rw-r--r--.1 liveuser liveuser 32 Aug 3 22:33 example.sh
$ ./example.sh
bash: ./example.sh: Permission denied
$ chmod 0744 ./example.sh
$ ls -l ./example.sh
-rwxr--r--.1 liveuser liveuser 32 Aug 3 22:33 example.sh
$ ./example.sh
foo
$
</syntaxhighlight>
 
=== The {{mono|source}} builtin <span class="anchor" id="The source builtin"></span><span class="anchor" id="source"></span><span class="anchor" id="The dot builtin"></span><span class="anchor" id="dot"></span> ===
 
<!-- Important concepts:
[x] source files vs shell scripts
[x] Dotfiles
[x] Hidden files
[ ] source executes the contents of a file in the current shell
[ ] scripts execute the contents of a file in a subshell
-->
 
With the {{code| source}}, or synonymous {{code| .}} command, Bash reads and executes shell commands from any text file by name.<ref>
{{Cite web
| access-date = 26 August 2025
| publisher = [[Free Software Foundation, Inc.]]
| title = 4.1 Bourne Shell Builtins
| url = https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html
| website = gnu.org
}}
</ref>
 
=== Login and non-login shells <span class="anchor" id="Login and non-login shells"></span><span class="anchor" id="Login shells"></span><span class="anchor" id="Non-login shells"></span> ===
 
{{Main
| Session (computer science)
}}
 
<!-- Important concepts:
[x] GUI
[x] User login session
[x] Non-login shell in a terminal emulator
[x] How to close a terminal emulator
-->
Bash can be executed as a [[Login session|login shell]], or "[[session leader]]," in both interactive and non-interactive modes via the {{Code| --login}} option.
"Logging in" requires user [[authentication]].
For this reason, only one login shell exists per user session.
In GNU/Linux, a user's login shell is identified in the /etc/passwd file.
 
:<syntaxhighlight lang = console>
$ awk -F ':' '$1 ~ /root/' /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
</syntaxhighlight>
 
When a human user initiates a login session, this procedure often occurs in a [[graphical user interface]] (GUI).
When a user opens a [[terminal emulator]], the emulator executes a ''non-login'' instance of the user's login shell.
 
Logging out of a shell session from within a terminal emulator can be accomplished with the {{mono| exit}} command or, by default in Bash, pressing {{Keypress| Ctrl|d}}.
 
=== Startup {{Mono| source}} files <span class="anchor" id="Startup source files"></span><span class="anchor" id="Startup files"></span><span class="anchor" id="Dotfiles"></span> ===
 
{{Main
| Unix shell
| Hidden file and hidden directory
}}
 
<!-- Important concepts:
[x] source
[x] Shell startup files vs shell scripts
[x] Dotfiles can be executed in many different ways
[x] Dotfiles can influence many different things
-->
When Bash starts, it uses {{Code| source}} to execute commands in a variety of [[Hidden file and hidden directory#Unix and Unix-like environments|dotfiles]] (see lists below).<ref name="drdobbs">
{{Cite web
| access-date = 8 August 2025
| archive-date = 2 March 2021
| archive-url = https://web.archive.org/web/20210302212410/https://www.drdobbs.com/i-almost-get-a-linux-editor-and-compiler/184404693
| date = 1 July 2021
| first = Al
| last = Stevens
| quote = But virtually all the configure and install scripts that come with open-source programs are written for bash, and if you want to understand those scripts, you have to know bash.
| title = I Almost Get a Linux Editor and Compiler
| url = https://www.drdobbs.com/i-almost-get-a-linux-editor-and-compiler/184404693
| url-status = dead
| website = drdobbs.com
}}</ref>
These dotfiles, unlike shell scripts, typically have neither the execute permission enabled nor an [[Shebang (Unix) |hash-bang]].
By default Bash will source a somewhat different set of files, and in a different sequence, depending on:<ref>
{{Cite web
| access-date = 12 August 2025
| publisher = [[GNU Project]]
| title = Bash reference manual, 6.2 Bash startup files
| url = https://www.gnu.org/software/bash/manual/bash.html#Bash-Startup-Files-1
| website = [[Free Software Foundation, Inc.]]
}}</ref>
* How bash is called
** interactively, non-interactively, invoked with name {{Code| sh}}
* Which options are used
** {{Code| --login}}, {{Code| --rcfile}}, {{Code| --norc}}, {{Code| --posix}}
* Which environment variables are defined
** {{Code| BASH_ENV}}, {{Code| ENV}} , and
* Which files exist
** {{Code| /etc/profile}}
** {{Code| ~/.bash_profile}}
** {{Code| ~/.bash_login}}
** {{Code| ~/.profile}}
** {{Code| ~/.bash_logout}}, and
** {{Code| ~/.bashrc}} among others.
 
Of course, any startup file can also execute commands from any other file.
Startup files can affect shell behavior, terminal emulators, the [[X window system]] and the [[window manager]].
 
=== POSIX mode <span class="anchor" id="POSIX mode"></span><span class="anchor" id="POSIX"></span> ===
 
{{Main
| POSIX
| POSIX terminal interface
}}
 
<!-- Important concepts:
[x] Standardization
[x] Optional conformance
[x] Portability
[x] POSIX' functionality tradeoffs
[x] How to activate and disable POSIX mode
[x] How to detect POSIX mode
[x] Default mode vs POSIX mode, re features
[x] Different shells, different syntax requirements
[x] Linters
-->
The [[POSIX]] IEEE 1003.1 standard specifies a common set of definitions that any shell ''system application'' (bash, [[Almquist shell|dash]], [[Z shell|zsh]], etc.) may conform to.<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = Institute of Electrical and Electronics Engineers
| url = https://www.britannica.com/topic/Institute-of-Electrical-and-Electronics-Engineers
| website = britannica.com
}}</ref>
Any shell ''user script'' ({{Code| ./myscript.sh}}) written in conformance with POSIX guidelines should be executable by any shell ''system application'' that has [[implementation |implemented]] the POSIX specification.
As a result, there can be a reasonable expectation that POSIX-compliant scripts can be executed with success on any Unix or Unix-like operating systems which implements the POSIX standard ([[Linux]], [[OpenBSD]], [[Oracle Linux]], [[HP-UX]], etc.).
These scripts are considered "[[Porting |portable]]" as they are and without any further modifications.
The portion of POSIX that applies to shells and command line utilities is a subset of a larger group of [[POSIX terminal interface|POSIX standards]] that further specify how terminals and terminal emulators aught to function in order to also be considered portable.
 
When Bash is operating in POSIX mode, fewer features are available but the resulting code can be executed on a greater variety of operating systems.
 
To enable POSIX mode at the initialization of an interactive shell, Bash can be executed as either {{code|sh}}, {{Code| bash --posix}} or {{Code| bash -o posix}}.<ref name = tldp_psx>
{{Cite web
| access-date = 8 August 2025
| archive-date = 27 January 2012
| archive-url = https://web.archive.org/web/20120127105451/http://tldp.org/LDP/abs/html/portabilityissues.html
| first = Mendel
| last = Cooper
| publisher = ibiblio.org
| title = Advanced Bash Scripting Guide: 36.9: Portability Issues
| url = https://tldp.org/LDP/abs/html/portabilityissues.html
| url-status = live
| website = [[Linux Documentation Project]]
}}</ref>
To cause a script to be initialized in POSIX mode, one would use the either the hashbang {{Code| #! /bin/env sh}} or the less portable {{Code| #!/bin/sh}}.
When an instance of Bash is operating in POSIX mode, the environment variable {{Code| $POSIXLY_CORRECT}} is defined, and the value of the environment variable {{Code| $SHELLOPTS}} includes the string {{mono|posix}}.
 
:<syntaxhighlight lang="console">
$ declare -p POSIXLY_CORRECT
bash: declare: POSIXLY_CORRECT: not found
$ sh
$ declare -p POSIXLY_CORRECT
declare -- POSIXLY_CORRECT="y"
$
</syntaxhighlight>
 
The full list of features available in Bash which are not specified by POSIX is considerable.<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[Case Western Reserve University]]
| title = 6.11 Bash and POSIX
| url = https://tiswww.case.edu/php/chet/bash/POSIX
| website = case.edu
}}</ref>
Here is a partial list:
{{div col|rules=yes}}
* Any arrays other than the array of positional parameters, {{Code| $@}}, are not POSIX
* The double bracket extended test construct, {{Code| [[...]]}}, is not POSIX
** {{Code| [...]}} and {{Code |test}} are POSIX
* One of the double-parentheses arithmetic-evaluation syntaxes, {{Code| ((...))}}, is not POSIX
** {{Code| $((...))}} is POSIX
* Brace expansion, <code>kernel{,-headers}</code>, is not POSIX
* Dynamic scoping of parameters and the {{Code |local}} builtin are not POSIX
* Process substitution, {{Code| <(...)}}, is not POSIX
* Certain string-manipulation operations in Parameter Expansions are not POSIX
* Most Bash builtin commands are not POSIX
** The command {{Code| enable -s| bash}} prints the list of Bourne Special Builtins, which are POSIX
**:<syntaxhighlight lang="console">
$ enable -s | wc --lines
16
$ enable | wc --lines
61
</syntaxhighlight>
** The {{Code |enable}} builtin itself is not POSIX
** In Bash, in non-POSIX mode, the {{Code| .}} and {{Code |source}} builtins are synonymous
*** The {{Code| .}} (i.e., 'dot') builtin ''is'' POSIX, however
*** The {{Code |source}} builtin ''is not'' POSIX
* The {{Code| $EPOCHSECONDS}} and {{Code| $EPOCHREALTIME}} shell variables are not POSIX<ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 3 June 2020
| archive-url = https://web.archive.org/web/20200603230615/https://www.shell-tips.com/linux/how-to-format-date-and-time-in-linux-macos-and-bash/#using-the-gnu-date-command-line
| date = 2 October 2020
| first = Nicolas
| last = Brousse
| title = How To Format Date And Time In Linux, MacOS, And Bash?
| url = https://www.shell-tips.com/linux/how-to-format-date-and-time-in-linux-macos-and-bash/#using-the-gnu-date-command-line
| url-status = live
| website = shell-tips.com
}}</ref>
{{div col end}}
System commands which are available in modern Unix-like operating systems, and which are also specified by POSIX may have fewer option flags or fewer relevant environment variables available under POSIX.
 
Because of these and other differences, modern (version 5) Bash shell scripts are rarely runnable "as-is" under the Bourne or legacy Korn shell interpreters.
Scripting with portability in mind is becoming less common as GNU/Linux becomes more widespread.<ref name =tldp_psx/><ref name = deb_pol>
{{Cite web
| access-date = 11 May 2020
| archive-date = 12 May 2020
| archive-url = https://web.archive.org/web/20200512050159/https://www.debian.org/doc/debian-policy/ch-files.html#scripts
| title = Debian Policy Manual v4.5.0.2: 10 - Files
| url = https://www.debian.org/doc/debian-policy/ch-files.html#scripts
| url-status = live
| website = debian.org
}}</ref>
 
Code that is valid syntax in Bash and yet is not specified by POSIX is called a "bashism." The program {{mono|checkbashisms}} can be used to make sure that a script can be executed in [[Debian |Debian Linux]] without any portability errors.<ref name = checkbashisms-1>
{{Man
|1|checkbashisms|ManKier
}}</ref>
Vidar Holen's {{mono|shellcheck}} is another static [[Lint (software) |linter]] written in [[Haskell]] which can parse script syntax for compatibility with any or all of bash, dash, ksh, and Bourne sh.<ref name = shellcheck-1>
{{Man
|1|shellcheck|ManKier
}}</ref>
The syntax requirements for each shell are each a little different.
For example, Debian's policy allows some extensions in their scripts (as they are in the [[Almquist shell#Dash|dash]] shell),<ref name =deb_pol/> while a script intending to support pre-POSIX Bourne shells, like [[autoconf]]'s {{mono|configure}}, are even more limited in the features they can use.<ref>
{{Cite web
| access-date = 20 January 2020
| archive-date = 2 March 2021
| archive-url = https://web.archive.org/web/20210302212413/https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.70/html_node/Portable-Shell.html
| publisher = [[GNU Project]]
| title = Autoconf: 11: Portable Shell
| url = https://www.gnu.org/software/autoconf/manual/html_node/Portable-Shell.html
| url-status = live
| website = [[Free Software Foundation, Inc.]]
}}</ref>
 
=== Other modes ===
 
* '''Restricted mode''': {{section link||Restricted mode}}.
 
* '''Privileged mode''' <span class="anchor" id="Privileged mode"></span>
 
<!-- Important concepts:
Saying something about Privileged mode
-->
: In Bash, "privileged mode" is a rarely used option inherited {{CN|date=August 2025}} from the SVR4.2 [[UNIX System V]] shell (circa 1992).<ref>
{{Cite web
| access-date = 13 August 2025
| publisher = [[GNU Project]]
| quote = In a questionable attempt at security, the SVR4.2 shell, when invoked without the -p option, will alter its real and effective UID and GID....
| title = Bash Reference Manual, B.1 Implementation Differences from the SVR4.2 Shell
| url = https://www.gnu.org/software/bash/manual/bash.html#Implementation-Differences-From-The-SVR4_002e2-Shell
| website = [[Free Software Foundation, Inc.]]
}}</ref> It can be enabled with {{Code| set -p| bash}} and disabled with {{Code| set +p| bash}}.<ref>
{{Cite web
| access-date = 13 August 2025
| publisher = [[GNU Project]]
| quote = In this mode, the $BASH_ENV and $ENV files are not processed, shell functions are not inherited from the environment, and the SHELLOPTS, BASHOPTS, CDPATH and GLOBIGNORE variables, if they appear in the environment, are ignored....
| title = Bash Reference Manual, 4.3.1 The Set Builtin
| url = https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
| website = [[Free Software Foundation, Inc.]]
}}</ref> When privileged mode is enabled, the {{Code| $SHELLOPTS| bash}} shell variables includes the string, "privileged."
 
* '''Extended debugging mode''' <span class="anchor" id="Extended debugging mode"></span>
 
<!-- Important concepts:
[x] Saying something about Extended debugging mode
-->
: Enabled via {{Code| bash --debugger}} at invocation or via {{Code| shopt -s extdebug| bash}} during either interactive or non-interactive modes. It uses a separate program called {{mono|bashdb}}.<ref name = ref_bashdb>
{{Cite web
| access-date = 18 August 2025
| title = BASH Debugger
| url = https://bashdb.sourceforge.net/
| website = sourceforge.net
}}</ref> {{mono|extdebug}} is not available in POSIX mode. See documentation for more information. See also {{Section link||Debugging}}.
 
* '''Compatibility modes''' <span class="anchor" id="Compatibility modes"></span>
 
<!-- Important concepts:
[x] Saying something about Compatibility modes
-->
{{Quote
| Bash-4.0 introduced the concept of a shell compatibility level, specified as a set of options to the shopt builtin (compat31, compat32, compat40, compat41, and so on). There is only one current compatibility level – each option is mutually exclusive. The compatibility level is intended to allow users to select behavior from previous versions that is incompatible with newer versions while they migrate scripts to use current features and behavior. It's intended to be a temporary solution.<ref>
{{Cite web
| access-date = 5 August 2025
| author = [[Free Software Foundation]]
| publisher = [[GNU Project]]
| title = Bash Reference Manual, 6.12 Shell Compatability Mode
| url = https://www.gnu.org/software/bash/manual/bash.html#Shell-Compatibility-Mode
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| author = Bash Reference Manual, 6.12 Shell Compatability Mode
}}
 
== Observability <span class="anchor" id="Observability"></span> ==
 
=== The {{mono| xtrace}} option ===
 
<!-- Important concepts:
[x] Description and visual example of xtrace
[x] How to enable and disable xtrace
[x] xtrace re POSIX
-->
When {{Mono| xtrace}} is enabled, simple debugging content is printed to the terminal.
It can be enabled with {{Code| set -o xtrace}} or {{Code| set -x}}, and disabled with {{Code| set +o xtrace}}, {{Code| set +x}} or {{Code| set -}}.
These options are also accepted at the commandline and at hash-bangs: {{Code| #!/bin/bash -x}}, etc.
 
<syntaxhighlight lang = console>
$ bash -x
$ echo $(( 2 + 2 ))
+ echo 4
4
$ set -- 1 2 3
$ printf '<%s>\n' "$@"
+ printf '<%s>\n' 1 2 3
<1>
<2>
<3>
$
</syntaxhighlight>
 
The {{Mono| xtrace}} shell setting is specified by POSIX.
See also {{section link||Debugging}}.
 
=== The {{mono| verbose}} option ===
 
<!-- Important concepts:
[x] Saying something about Verbose mode
-->
The verbose option prints strings to the terminal as they are read, and before any expansions are performed. Rarely used.<ref>See {{Code| set -v| bash}} in the documentation.</ref>
 
=== Comments ===
 
<!-- Important concepts:
[x] Comments
[x] Inline comments
[x] Observability of comments
-->
Comments can be a valuable way of clarifying information or explaining a script or source file to someone else who might not be familiar with the scripter's intentions or context.
 
Standard comments in Bash are denoted with a hashtag character: {{char|#}}.
Any text to the right of the hashtag to the end of the line will be ignored.
Inline comments are allowed, but hashtag comments will not print during debugging. See also: {{section link||xtrace}}.
 
Comments denoted with a colon character, {{char|:}}, originated with the [[Thompson shell]].<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = Ken Thompson
| url = https://www.britannica.com/biography/Kenneth-Lane-Thompson
| website = britannica.com
}}</ref>
Any arguments to the right of colon {{char|:}} builtin are ignored.
Inline comments are not possible, but colon comments will print during debugging and any parameters will have been expanded.
<ref>
{{Cite web
| access-date = 8 August 2025
| at = Base Specifications Issue 8: IEEE Std 1003.1-2024
| author = The Open Group
| title = 2.15 Special Builtins: colon - null utility
| url = https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_17
| website = opengroup.org
}}</ref>
 
:<syntaxhighlight lang="console">
$ # Define foo
$ foo=bar # An inline hashtag comment occurs on the same line as a command
$ set -x
$ # A regular comment (no output)
$ : "${foo}"
+ : bar
$
</syntaxhighlight>
 
=== Exit codes ===
 
<!-- Important concepts:
[x] What exit codes signify: success vs partial success vs failure
[x] The question mark '$?' special variable
[x] Boolean algebra
[x] Look for intended meaning in the man page
[x] Arithmetic contexts are different
[x] Lack of standardization
-->
When bash executes commands, [[exit status]] codes, also called "return codes," are produced which can offer some insight into the manner in which a program ceased running.
The value of the most recently captured exit code is held within the shell parameter, 'question mark:' {{Code| $? }}.
In non-arithmetic contexts, (i.e., most of the time) the numerical or "[[Boolean algebra|Boolean]]" value of "true" is zero (0), and the value of "false" is one (1).
 
When a system command has executed, the intended meaning of its exit status can most often be found in its man page; usually a zero indicates success and a nonzero exit status indicates some kind of failure condition or partial success.
{{Code| ping}} is a well known command with three meaningful exit codes: 0, 1, and 2.
 
In Bash, within arithmetic contexts, the numerical truth values are reversed: "true" is one and "false" is zero.
An arithmetic context can usually be identified by the syntax {{Code| ((...)) }} or {{Code| $((...)) }}.
If an arithmetic statement evaluates to the integer zero, then the statement is considered "true," and the exit code is one.
If the statement evaluates to any number other than zero the arithmetic statement is "false" and the exit code is zero.
 
Not all Linux/UNIX commands provide meaningful exit codes beyond zero and one, and there is no standard system for definitions of exit codes in Linux.
 
:<syntaxhighlight lang="console">
$ true; echo "$?" # Exit code means "true"
0
$ false; echo "$?"; echo # Exit code means "false"
1
$
$ bash -c 'exit 99'; printf 'exit-code: %d\n\n' "$?"
exit-code: 99
$
$ (( 1 - 1 )); printf '%d\n' "$?" # This exit code means "true"
1
$ (( 1 + 1 )); printf '%d\n' "$?" # ...and this exit code means "false"
0
</syntaxhighlight>
 
=== Job control ===
 
{{Main
| Job control (Unix)
}}
 
<!-- Important concepts:
[x] Terminal emulator
[x] Interactive mode
[x] Job = process
[x] Background vs foreground
[x] Suspending, resuming
[?] Process states
[x] How to control jobs, incl related commands
[ ] disown
-->
The Bash shell has two modes of execution for commands: batch (asynchronous), and concurrent (synchronous).
To execute commands in batch mode (i.e., in sequence) they must be separated by the character {{char|;}}, or on separate lines:
 
:<syntaxhighlight lang="console">
$ command1; command2
$ command3
$
</syntaxhighlight>
 
In this example, when {{Mono| command1}} is finished, {{Mono| command2}} is executed, and when {{Mono| command2}} has completed, {{Mono| command3}} will execute.
A [[Background process |background execution]] of {{Mono| command1}} can occur using symbol {{char|&}} at the end of an execution command, and process will be executed in background while immediately returning control to the shell and allowing continued execution of commands.
 
:<syntaxhighlight lang="console">
$ command1 &
$
</syntaxhighlight>
 
Or to have a concurrent execution of {{Mono| command1}} and {{Mono| command2}}, they must be executed in the Bash shell in the following way:
 
:<syntaxhighlight lang="console">
$ command1 & command2
$
</syntaxhighlight>
 
In this case {{Mono| command1}} is executed in the background, {{char|&}} symbol, returning immediate control to the shell that executes {{Mono| command2}} in the foreground.
A process can be stopped and control returned to bash by typing {{Key press|Ctrl|z}} while the process is running in the foreground.<ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 15 March 2018
| archive-url = https://web.archive.org/web/20180315115230/http://www.gnu.org/software/bash/manual/bash.html#index-background
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 7.1 Job Control Basics
| url = https://www.gnu.org/software/bash/manual/bash.html#index-background
| url-status = live
| website = [[Free Software Foundation, Inc.]]
}}</ref>
A list of all processes, both in the background and stopped, can be achieved by running {{mono|jobs}}:
 
:<syntaxhighlight lang="console">
$ jobs
[1]- Running command1 &
$
</syntaxhighlight>
In the output, the number in brackets refers to the job id.
The plus sign signifies the default process for {{mono|bg}} and {{mono|fg}}.
The text "Running" and "Stopped" refer to the [[process state]].
The last string is the command that started the process.
The state of a process can be changed using various commands.
The {{mono|fg}} command brings a process to the foreground, while {{mono|bg}} sets a stopped process running in the background.
{{mono|bg}} and {{mono|fg}} can take a job id as their first argument, to specify the process to act on.
Without one, they use the default process, identified by a plus sign in the output of {{mono|jobs}}.
The {{mono|kill}} command can be used to end a process prematurely, by sending it a [[Signal (IPC)|signal]].
The job id must be specified after a percent sign:
:<syntaxhighlight lang = console>
$ sleep 100 &
[1] 4904
$ kill %1
$ jobs
[1]+ Terminated sleep 100
$
</syntaxhighlight>
 
Job control, also known as "Monitor mode," is enabled by default in interactive shells, and can be disabled with {{Code|set +m|bash}}.
 
=== Signals ===
 
<!-- More citations in this section, please! -->
<!-- Important concepts:
[x] Process
[x] Execution
[x] Interactive terminal
[x] Control keypress sequences
[x] Foreground vs. background processes
[ ] TTY's
[?] sleep builtin
[?] `ps aux`, `grep` and `awk`
[ ] Variety of signals
[ ] Utility of certain signals: KILL, TERM, etc
[x] Sending signals: kill
[ ] Catching signals: trap
[x] Bash special signals
-->
[[Signal (IPC)|Signaling]] is a means of [[inter-process communication]] (IPC). Sometimes a commandline process may seem to freeze in the middle of execution.
In these instances it may become necessary to identify which process may be blocked and to manually end the offending process.
 
At an interactive terminal, it is usually sufficient to press {{key| Ctrl-c}} to end the current foreground process and return control back to the user prompt, or to press {{key| Ctrl-z}} to suspend it.
Occasionally attempting to suspend a process will succeed when attempts to cancel a process appear unresponsive.
In other cases it may be necessary to use the {{Mono| kill}} program to send an IPC signal.
In this example, we use the {{Mono| kill}} command from a second terminal screen to terminate the process with PID 4331.
 
:<syntaxhighlight lang = console>
$ tty # Terminal one
/dev/pts/0
$ whoami
liveuser
$ sleep 1000 # Command hangs
</syntaxhighlight>
 
:<syntaxhighlight lang = console>
$ tty # Terminal two
/dev/pts/1
$ whoami
liveuser
$ ps aux | grep -e sleep -e PID
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
liveuser 4331 0.0 0.0 230336 2312 pts/1 S+ 11:19 0:00 sleep 1000
liveuser 4333 0.0 0.0 231248 2516 pts/0 S+ 11:19 0:00 grep --color=auto -e sleep -e PID
$ kill 4331
$ ps aux | grep -e sleep -e PID # The sleep process has ended
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
liveuser 4333 0.0 0.0 231248 2516 pts/0 S+ 11:19 0:00 grep --color=auto -e sleep -e PID
$
</syntaxhighlight>
 
:<syntaxhighlight lang = console>
$ tty # Terminal one again
/dev/pts/0
$ whoami
liveuser
$ sleep 1000
Terminated
$
</syntaxhighlight>
 
In Unix-like operating systems, a user is allowed to instruct the kernel to send a signal to a process that is owned by the user.
A regular user may not send a signal to a privileged process.
Signals can be sent to a process using the {{mono| kill}} builtin or using the system binary of the same name.
 
:<syntaxhighlight lang = console>
$ whoami
liveuser
$ ps aux | awk '$2 ~ /\<1\>/' # Let\s view some info on the kernel process, process 1.
root 1 0.0 0.2 37140 20440 ? Ss 04:44 0:18 /usr/lib/systemd/systemd --switched-root --system --deserialize=53 rhgb
$ kill -s SIGKILL 1
bash: kill: (1) - Operation not permitted
$ type -a kill
kill is a shell builtin
kill is /usr/bin/kill
$ /usr/bin/kill -s SIGKILL 1
kill: sending signal to 1 failed: Operation not permitted
$
</syntaxhighlight>
 
The most commonly used signals can be viewed with <CODE>kill -L | head -n 4</CODE>.
Each IPC signal is associated with a signal number, but exit codes and signal codes are two different things.
While sending a process an IPC signal of 9 (a "KILL" signal) will almost certainly terminate the process immediately, it will most likely not result in the process returning an exit code of 9.
 
<!-- How cleanly do processes shut down on INT and QUIT? -->
<!-- Is Ctrl-z SIGSTOP or SIGTSTP? -->
By default in Bash, builtin kill sends a TERM ("terminate") signal.
It's common for commandline utilities to respond to a SIGTERM by shutting down and exiting cleanly.
The Ctrl-c keypress sequence in Bash sends a SIGINT, interrupt signal, to the foreground process.
The Ctrl-z keypress sequence sends the SIGSTOP, stop signal.<ref>
{{Cite book
| access-date = 16 August 2025
| date = 2008
| first = Randal
| isbn = 978-0-470-18301-4
| last = Michael
| page = 25
| publisher = Wiley Publishing, Inc., Indianapolis, Indiana
| quote = 19 :: SIGSTOP :: Stop, usually Ctrl + z
| title = Mastering Unix Shell Scripting, 2e
| url = https://books.google.com/books?id=uI7C2BDF6F0C
}}</ref>
When a process receives a SIGKILL, the process terminates immediately and messily.
It is recommended to use SIGKILL only as a last resort.<ref>
{{Cite book
| access-date = 16 August 2025
| date = 29 March 2005
| first = Cameron
| last = Newham
| page = 205
| publisher = O'Reilly Media, Inc.
| quote = Use KILL only as a last resort!
| title = Learning the bash Shell: Unix Shell Programming
| isbn = 978-0-596-55500-9
| url = https://books.google.com/books?id=dzBCH3x6fYEC
}}</ref>
The SIGKILL signal cannot be blocked or handled.
 
Processes can "catch" and "handle" IPC signals they receive.
A user can use the kill builtin to "send" an IPC signal to another process.
That target process can set up a mechanism, some plan beforehand, for how to repsond whenever any particular signal might be received, or "caught."
The way a target program responds is referred to as how the program "handles" receiving the signal.
In the man pages one can see how some system commands will print out certain information to the terminal when they receive a SIGHUP: for example, the {{Code| dd| bash}} command.{{CN|date=August 2025}}
 
{{Blockquote
| When bash is interactive, in the absence of any traps, it ignores {{mono|SIGTERM}} (so that {{Code| kill 0| bash}} does not kill an interactive shell), and catches and handles {{mono|SIGINT}} (so that the {{mono| wait}} builtin is interruptible). When bash receives {{mono|SIGINT}}, it breaks out of any executing loops. In all cases, bash ignores {{mono|SIGQUIT}}. If job control is in effect, bash ignores {{mono|SIGTTIN}}, {{mono|SIGTTOU}}, and {{mono|SIGTSTP}}.<ref name = case.edu_bash(1)>
{{Cite web
| access-date = 8 August 2025
| publisher = [[Case Western Reserve University]]
| title = Bash(1)
| url = https://tiswww.case.edu/php/chet/bash/bash.html
| website = case.edu
}}</ref>
| author = {{Mono| bash(1)}}
}}
 
By default Bash shell scripts receive and respond to any and all IPC signals sent to them, however, Bash scripts can utilize the {{mono| trap}} builtin to catch and handle signals.<ref>
{{Cite web
| access-date = 5 August 2025
| title = Sending and Trapping Signals
| url = https://mywiki.wooledge.org/SignalTrap
| website = wooledge.org
}}</ref>
 
:<syntaxhighlight lang = console>
$ cat ./trap-example.sh
#! /usr/bin/env bash
trap umask EXIT
echo bar
exit 0
$ chmod 0700 trap-example.sh
$ ./trap-example.sh
bar
0077
$
</syntaxhighlight>
 
There are a few signals which are only available from within Bash as GNU extensions: {{mono|ERR}}, {{mono|EXIT}}, {{mono|RETURN}} and {{mono|DEBUG}}.
These signals can be useful in debugging, and can only be sent and handled by shell builtins.
See also {{Section link|| Debugging}}.
 
=== Values of parameters ===
 
<!-- Important concepts:
[ ] re Variables
[?] Accuracy in observing contents of variables
[x] String
[x] Attributes
[x] String values vs attributes of variables
[x] Special Variables
[x] printf
[x] declare -p
[?] Commandline parsing
-->
There are many different implementations of {{mono|echo}}. Some have the {{code|-e}} option, and some don't.<ref>
{{Cite book
| access-date = 16 August 2025
| date = 2008
| first = Randal
| isbn = 978-0-470-18301-4
| last = Michael
| page = 20
| publisher = Wiley Publishing, Inc., Indianapolis, Indiana
| quote = In Korn shell the {{Mono |echo}} command recognizes these command options by default. In Bash shell we must add the {{Mono |-e}} switch to the {{Mono |echo}} command, {{Code| echo -e "\n"| bash}} for one new line.
| title = Mastering Unix Shell Scripting, 2e
| url = https://books.google.com/books?id=uI7C2BDF6F0C
}}</ref>
The list of options is not uniform across implementations, though {{mono|echo}} and {{mono|printf}} are both specified by POSIX.
If a scripter wishes to know the precise value of a string contained by a variable, then the most consistent way of doing so is to use {{mono|printf}}.
 
For any string containing any character (besides null?) including digits, the format specifier is {{mono|%s}}.{{CN|date=August 2025}}
 
:<syntaxhighlight lang="console">
$ foo=abc bar=123
$ printf '<%s>\n' "${foo}" "${bar}"
<abc>
<123>
$
</syntaxhighlight>
 
For digits only, the format specifier is {{mono|%d}}.
 
:<syntaxhighlight lang="console">
$ printf '<%d>\n' "${foo}" "${bar}"
bash: printf: abc: invalid number
<0>
<123>
$
</syntaxhighlight>
 
With {{mono|printf}}, a newline is never included in the output unless the scripter includes a newline in the format string.
In the example below, where a newline has been omitted from the format string, the value of PS1 is printed on the same line as the output of the previous command.
 
:<syntaxhighlight lang="console">
$ printf '<%s>' "${foo}" "${bar}"
<abc><123>$
</syntaxhighlight>
 
Another very consistent method is to use {{Code|declare -p| bash}}.
The output of {{Code|declare -p| bash}} can be reused as input.
However, not all variables and parameters can be printed using {{Code|declare -p| bash}}, for example, the values of the Special Parameters.
The Special Parameter hashtag, {{Code|"$#"| bash}}, reports how many Positional Parameters are currently defined.
 
:<syntaxhighlight lang="console">
$ declare -p foo bar
declare -- foo="abc"
declare -- bar="123"
$ declare -p "$#"
bash: declare: 0: not found
$
</syntaxhighlight>
 
For a full string of input at an interactive shell...
 
:<syntaxhighlight lang="console">
$ declare -p #
</syntaxhighlight>
 
...the hashtag would be interpreted by Bash as an inline comment.
With the comment and all text to the right of it removed, the command that Bash would execute would be {{Code|declare -p| bash}}.
This command would, according to {{code|help declare}}, "display the values and attributes of each NAME," i.e., each variable, and, "if no NAMEs are given, display the values and attributes and values of all variables," which can be over 100 lines of output.
 
On the other hand, {{mono|printf}} cannot display variables' attributes.
See also {{section link||Debugging}}.
 
:<syntaxhighlight lang="console">
$ readonly foo
$ declare -p foo
declare -r foo="abc"
$ printf '<%s>' "${foo}"
<abc>
$
</syntaxhighlight>
<!--=== Variables ===-->
<!-- Important concepts:
[x] Character encoding
[x] Control characters
[x] String
[x] Attributes
[ ] Expansion
[x] Observability of comments
[x] Working directory (PWD) [Environment]
[x] PS1, re visual examples [Environment]
[x] Shell startup files vs shell scripts [Environment]
[x] Dotfiles can be executed in many different ways
[x] Dotfiles can influence many different things
[x] How to detect POSIX mode: POSIXLY_CORRECT [Environment]
[ ] Dynamic scope - local vs global
[ ] Define PATH variable [Environment]
[ ] Use of PATH
[ ] Command position, exception re variable assignment [Environment]
[ ] Subshells: Process and environment info, ie, parent/child, exact copy, etc
[ ] Subshells: SHLVL and PROPMT_COMMAND [Environment]
[ ] Subshells: export and limitations of variables
 
[ ] Arrays
-->
 
=== Environment ===
 
{{How-to|date=January 2019}}
<!-- This subsection has been marked as "contains instructions or advice" since 2019. -->
<!--
[ ] See also 'Startup source files'
[x] Debugging dotfiles can be difficult
[?] We aught to avoid assigning blame
-->
Configurable execution environment(s):<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 3.7.3: Command Execution Environment
| url = https://www.gnu.org/software/bash/manual/html_node/Command-Execution-Environment.html
| website = [[Free Software Foundation, Inc.]]
}}</ref>
* Shell and [[Session (computer science)|session]] startup files such as {{Code| ~/.bashrc}} and {{Code| ~/.profile}} (i.e., [[Hidden file and hidden directory|dotfiles]]);
* Settings ({{mono|set}} [[Shell builtin|built-in]]) and shell options ({{mono|shopt}} [[Shell builtin|built-in]]) which alter shell behavior;
 
Shell and session startup Files (a.k.a., "dot files")
 
When Bash starts, it executes the commands in a variety of [[Hidden file and hidden directory#Unix and Unix-like environments|dot files]].<ref name="drdobbs" />
Unlike Bash shell scripts, dot files do typically have neither the execute permission enabled nor an [[interpreter directive]] like {{Code| #!/bin/bash}}.
 
* Legacy-compatible Bash startup example
 
The example {{Code| ~/.bash_profile}} below is compatible with the Bourne shell and gives semantics similar to csh for the {{Code| ~/.bashrc}} and {{Code| ~/.bash_login}}.
The <code>[ -r ''filename'' ] && cmd</code> is a [[short-circuit evaluation]] that tests if ''filename'' exists and is readable, skipping the part after the {{Code| &&}} if it is not.
 
:<syntaxhighlight lang="bash">
[ -r ~/.profile ] && ~/.profile # set up environment, once, Bourne-sh syntax only
if [ -n "$PS1" ]; then # are we interactive?
[ -r ~/.bashrc ] && ~/.bashrc # tty/prompt/function setup for interactive shells
[ -r ~/.bash_login ] && ~/.bash_login # any at-login tasks for login shell only
fi # End of "if" block
</syntaxhighlight>
 
* Operating system issues in Bash startup
 
Some versions of [[Unix]] and [[Linux]] contain Bash system startup scripts, generally under the {{Code| /etc}} directory.
Bash executes these files as part of its standard initialization, but other startup files can read them in a different order than the documented Bash startup sequence.
The default content of the root user's files may also have issues, as well as the skeleton files the system provides to new user accounts upon setup.
The startup scripts that launch the [[X window system]] may also do surprising things with the user's Bash startup scripts in an attempt to set up user-environment variables before launching the [[window manager]].
These issues can often be addressed using a {{Code| ~/.xsession}} or {{Code| ~/.xprofile}} file to read the {{Code| ~/.profile}} — which provides the environment variables that Bash shell windows spawned from the window manager need, such as [[xterm]] or [[Gnome Terminal]].
 
=== Standard streams ===
 
[[Standard streams]] - STDIN, STDOUT and STDERR
 
== Commands <span class="anchor" id="Commands"></span> ==
<!-- Important concepts
[ ] Speed of execution
[ ] fork(2) / exec(2)
[ ? ] type -a
-->
 
=== System commands <span class="anchor" id="System commands"></span> ===
 
<!-- What are system commands? -->
<!-- Why does Bash have system commands?-->
<!-- When should system commands be used? -->
<!-- How does one use system commands? -->
 
=== Aliases <span class="anchor" id="Aliases"></span> ===
 
<!-- Important concepts:
[x] Command position
[ ] Expansion
[ ] Trailing spaces in alias definitions
[ ] Mostly superceded by functions
[ ] alias names can be nearly anything
-->
<!-- What are aliases? -->
<!-- Why does Bash have aliases?-->
<!-- When should aliases be used? -->
<!-- How are aliases and system commands different/similar? -->
<!-- How does one use aliases? -->
 
{{Blockquote
| Aliases allow a string to be substituted for a word that is in a position in the input where it can be the first word of a simple command. Aliases have names and corresponding values that are set and unset using the alias and unalias builtin commands.
| author = GNU Bash Reference Manual, Ch 6.6 Aliases<ref>
{{Cite web
| access-date = 14 August 2025
| publisher = [[GNU Project]]
| quote = Aliases allow a string to be substituted for a word that is in a position in the input where it can be the first word of a simple command. Aliases have names and corresponding values that are set and unset using the alias and unalias builtin commands.
| title = Bash Reference Manual, 6.6 Aliases
| url = https://www.gnu.org/software/bash/manual/html_node/Aliases.html
| website = [[Free Software Foundation, Inc.]]
}}</ref><ref>
{{Cite web
| access-date = 14 August 2025
| publisher = The Open Group
| title = alias - define or display aliases
| url = https://pubs.opengroup.org/onlinepubs/9799919799/utilities/alias.html
| website = opengroup.org
}}</ref><ref>
{{Cite web
| access-date = 14 August 2025
| first = Mendel
| last = Cooper
| title = Advanced Bash Scripting Guide, Ch 25. Aliases
| url = https://tldp.org/LDP/abs/html/abs-guide.html#ALIASES
| website = [[Linux Documentation Project]]
}}</ref><ref>
{{Cite web
| access-date = 14 August 2025
| title = Commands and Arguments: Aliases
| url = https://mywiki.wooledge.org/BashGuide/CommandsAndArguments?highlight=%28alias%29#Aliases
| website = wooledge.org
}}</ref><ref>
{{Cite web
| access-date = 14 August 2025
| title = Compound Commands: Aliases
| url = https://mywiki.wooledge.org/BashGuide/CompoundCommands?highlight=%28alias%29#Aliases
| website = wooledge.org
}}</ref>
| style =
}}
 
=== Keywords / Reserved Words<span class="anchor" id="Keywords / Reserved words"></span> <span class="anchor" id="Keywords"></span> <span class="anchor" id="Reserved words"></span> ===
 
<!-- Important concepts:
[ ] "Reserved words" limitations
[ ] Compound commands
[ ] List
-->
<!-- What are Reserved Words? -->
<!-- Why does Bash have Reserved Words?-->
<!-- When should Reserved Words be used? -->
<!-- How are Reserved Words and different/similar from anything else? -->
<!-- How does one use Reserved Words? -->
 
* {{Code| function}}
** Bash function declarations which include this particular keyword are not compatible with Bourne/Korn/POSIX scripts, however, Bash does accepts the function declaration syntax used by Bourne, Korn and POSIX-compliant shells.
 
=== Functions <span class="anchor" id="Functions"></span> ===
 
<!-- Important concepts:
[x] Command position
[ ] Expansion
[ ] Functions superceded aliases, mostly
[ ] Function names can be nearly anything
[ ] Dynamic scope - local vs global
[ ] Limitations of functions
-->
<!-- What are functions? -->
<!-- Why does Bash have functions?-->
<!-- When should functions be used? -->
<!-- How are functions and aliases different/similar? -->
<!-- How does one use functions? -->
 
{{Blockquote
| Shell functions are a way to group commands for later execution using a single name for the group. They are executed just like a "regular" simple command. When the name of a shell function is used as a simple command name, the shell executes the list of commands associated with that function name. Shell functions are executed in the current shell context; there is no new process created to interpret them.
| author =  GNU Bash Reference Manual, Ch 3.3 Shell Functions<ref>
{{Cite web
| access-date = 14 August 2025
| publisher = [[GNU Project]]
| quote = Shell functions are a way to group commands for later execution using a single name for the group. They are executed just like a "regular" simple command. When the name of a shell function is used as a simple command name, the shell executes the list of commands associated with that function name. Shell functions are executed in the current shell context; there is no new process created to interpret them.
| title = Bash Reference Manual, 3.3 Shell Functions
| url = https://www.gnu.org/software/bash/manual/html_node/Shell-Functions.html
| website = [[Free Software Foundation, Inc.]]
}}</ref><ref>
{{Cite web
| access-date = 14 August 2025
| publisher = The Open Group
| title = 2.9.5 Function Definition Command
| url = https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_09_05
| website = opengroup.org
}}</ref><ref>
{{Cite web
| access-date = 14 August 2025
| first = Mendel
| last = Cooper
| title = Advanced Bash Scripting Guide, Ch 24. Functions
| url = https://tldp.org/LDP/abs/html/abs-guide.html#FUNCTIONS
| website = [[Linux Documentation Project]]
}}</ref><ref>
{{Cite web
| access-date = 14 August 2025
| title = Compound Commands, 4. Functions
| url = https://mywiki.wooledge.org/BashGuide/CompoundCommands?highlight=%28functions%29#Functions
| website = wooledge.org
}}</ref><ref>
{{Cite web
| access-date = 14 August 2025
| title = Bash Programming, 2. Basic Concepts, 7. Functions
| url = https://mywiki.wooledge.org/BashProgramming?highlight=%28functions%29#Functions
| website = wooledge.org
}}</ref><ref>
{{Cite web
| access-date = 14 August 2025
| title = Bash Weaknesses, 13. Functions
| url = https://mywiki.wooledge.org/BashWeaknesses?highlight=%28functions%29
| website = wooledge.org
}}</ref>
| style =
}}
 
=== Builtin commands <span class="anchor" id="Builtin commands"></span> <span class="anchor" id="Builtins"></span> ===
 
<!-- Important concepts:
[ ] Varying options, builtins vs binaries
[ ] POSIX / Bourne Special builtins
[ ] enabling / disabling builtins
[ ] loading custom builtins
[ ] Partial list of builtins
-->
<!-- What are builtin commands? -->
<!-- Why does Bash have builtin commands?-->
<!-- When should builtin commands be used? -->
<!-- How are builtin and system commands different/similar? -->
<!-- How does one use builtin commands? -->
 
* Various Built-In Commands:
** POSIX Special builtins:<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 4.1: Bourne Shell Builtins
| url = https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html
| website = [[Free Software Foundation, Inc.]]
}}</ref>
*** {{mono|cd}}, {{mono|pwd}}, etc.
** {{mono|set}}<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 4.3.1: The Set Builtin
| url = https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
| website = [[Free Software Foundation, Inc.]]
}}</ref>
*** Xtrace: [ {{Code| set -x| bash}} | {{Code| set -o xtrace| bash}} ]. The shell's primary means of debugging. Both xtrace and verbose can be turned off at the same time with the command {{Code| set -| bash}}.
*** Verbose: [ {{Code| set -v| bash}} | {{Code| set -o verbose| bash}} ]. Prints a command to the terminal as Bash reads it. Bash reads constructs all at once, such as compound commands which include if-fi and case-esac blocks. If a {{Code| set -v| bash}} is included within a compound command, then "verbose" will be enabled the next time Bash reads code as input, i.e., after the end of the currently executing construct.<ref>
{{Cite mailing list
| access-date = 8 August 2025
| date = 20 April 2021
| publisher = [[GNU Project]]
| mailing-list = bug-bash
| title = bug-bash archives, Re: Document that set -v inside case statements is special
| url = https://lists.gnu.org/archive/html/bug-bash/2021-04/msg00172.html
}}</ref>
*** Both xtrace and verbose can be turned off at the same time with the command {{Code| set -| bash}}.
** {{mono|shopt}}<ref name = bash-hackers.org_changes>
{{Cite web
| access-date = 8 August 2025
| archive-date = 23 September 2019
| archive-url = https://web.archive.org/web/20190923203509/https://wiki-dev.bash-hackers.org/scripting/bashchanges
| title = Bash changes
| url = https://wiki-dev.bash-hackers.org/scripting/bashchanges
| url-status = dead
| website = bash-hackers.org
}}</ref>
*** expand-aliases: On by default in interactive shells. Some developers discourage its use in scripts.
 
=== PATH and system commands <span class="anchor" id="PATH and system commands"></span> <span class="anchor" id="PATH"></span> <span class="anchor" id="System commands"></span> ===
 
<!-- Prose is messy -->
<!-- Important concepts:
[x] Bourne shell variables
[x] Define PATH
[x] Common practices, mutability
[ ] Internal commands
[ ? ] How Bash performs a PATH search
[x] Multiple commands with the same name
[ ? ] Speed considerations
[ ? ] How to force a PATH search - extra?
[ ? ] security considerations
-->
When the shell looks for external commands, it relies on the Bourne shell variable {{Code| $PATH| bash}}. {{Code| $PATH| bash}} contains a list of directories separated by colons, {{Code| :| bash}}.
Beginning with the leftmost directory and selecting directories in a left to right pattern, each directory is searched until a match is found.
In Linux, so that a user can locate additional commands, it's common practice for distribution administrators and package developers to alter the value of an end user's {{Code| $PATH| bash}} by including source files in {{Code| /etc/profile.d| bash}} and other locations.
 
When looking for the command, {{Code| chmod| bash}}, for instance, after considering internal commands and finding nothing, Bash will search the directories in {{Code| $PATH| bash}} and will select the absolute path of the first executable found that has a basename which matches the search string. <ref name = tldp_3.2.1/>
 
If there is more than one command {{Code| echo| bash}} available in the directories listed in {{Code| $PATH| bash}}, during the process of parsing and executing a commandline, by default only the first command found will be selected.
{{Code| $PATH| bash}} lookups are slow.
The shell speeds up the commandline execution process by remembering command locations in a hash table.
To perform a full {{Code| $PATH| bash}} search without any interference from the hash table, remove the current table with {{Code| hash -r| bash}} and search for all kinds of commands with {{Code| type -a| bash}}.
 
:<syntaxhighlight lang = console>
$ # Force a full path search
$ PATH=${PATH}:${HOME}
$ printf 'echo script_file: "$@"\n' > ./echo
$ chmod 0700 ./echo
$ hash -r; type -a echo
echo is a shell builtin
echo is /usr/bin/echo
echo is /home/liveuser/echo
$
</syntaxhighlight>
 
In order to execute a commandline with a command found later in the {{Code| $PATH| bash}} string, you can specify an absolute path or you can anchor path resolution relative to the current working directory.
 
:<syntaxhighlight lang = console>
$ /home/liveuser/echo foo
script_file: foo
$ ./echo bar
script_file: bar
$
</syntaxhighlight>
 
For security reasons it is advisable to make sure the directories in PATH are not world-writeable, or are writeable only by root and trusted users.
 
=== Command lookup <span class="anchor" id="Command lookup"></span> ===
 
<!-- Important concepts:
[x] Command position
[?] Parsing full commandline
[ ] Order of name lookup
[ ] Use of PATH
[ ] Last step of command execution
-->
* Command position: after expansions, the first word of the full text of the command line.
* Command name lookup is performed, in the following order:
** [[Command (computing)|Commands]] internal to the [[Shell (computing)|shell]]:
*** [[Alias (command)|Shell aliases]],
*** Shell reserved words,
*** [[Function (computer programming)|Shell functions]], and
*** [[Shell builtin|Shell built-in commands]];
** Commands external to the shell, using the PATH shell variable:
*** Separate [[Unix|UNIX]]-style programs such as [[ls|{{mono|ls}}]] or [[Ln (Unix)|{{mono|ln}}]], and
*** [[Shell script]]s, which are [[File system|files]] containing executable commands.{{efn|name=script|Shell scripts do not require compilation before execution and, when certain requirements are met, can be invoked as commands by using their filename.}}
* The resulting string is executed as a command.
 
== Control structures <span class="anchor" id="Control structures"></span><span class="anchor" id="Control flow"></span> ==
 
{{See also-text|[[Control flow|Control structures]] for [[Conditional (computer programming)|Condition testing]] and [[short-circuit evaluation]]
}}
 
=== Subshells ===
 
<!-- Important concepts:
[ ] Subshells
[ ] Process and environment info, ie, parent/child, exact copy, etc
[ ] As each pertains to subshells:
[ ] Interactive invocation
[ ] `bash -c`, SHLVL and PROPMT_COMMAND
[ ] Scripts vs source files
[ ] Logging in as another user
[ ] Job control
[ ] export and limitations of variables
[ ] Functions -- https://www.oilshell.org/blog/2017/01/15.html
[ ] eval builtin
[ ] exec builtin
-->
[[Child process|Subshells]]: {{Code| (...)}};
 
=== Pipelines ===
 
<!-- Important concepts:
[ ] Input / output
[ ] STDIN, STDOUT, STDERR
[ ] File descriptors
[ ] Redirection
[ ] Subshell
-->
{{Blockquote
| However, by using a pipeline, they can engage in multiple cycles of computation at the same time, substantially increasing their speed. In a pipelined control unit, different instructions simultaneously go through the process but at different points. While one instruction is being fetched, a second is being decoded, and so forth.<ref name =Brit_control-unit/>
| author = [[Encyclopædia Britannica]]
| style =
}}
[[Unix|UNIX]]-style [[Pipeline (Unix)|pipelines]]: <CODE>|</CODE>.
 
=== Logical operators ===
 
<!-- Important concepts:
[x] Exit codes
[x] Pipelines
[ ] Conditional logic
[ ] Pitfall: not the same as if...fi
-->
* AND ({{Code| &&}})
* OR (<CODE>||</CODE>)
* NOT ({{Code| !}})
 
Bash supplies "conditional execution" command separators that make execution of a command contingent on the [[Exit status|exit code]] set by a precedent command.
For example:
 
<syntaxhighlight lang = console>
$ cd "$SOMEWHERE" && ./do_something || echo "An error occurred" >&2
</syntaxhighlight>
 
Where {{code|./do_something}} is only executed if the {{mono|cd}} (change directory) command was "successful" (returned an exit status of zero) and the {{mono|echo}} command would only be executed if either the {{mono|cd}} or the {{code|./do_something}} command return an "error" (non-zero exit status).
 
=== Iteration ===
 
{{Main
|Iteration#Computing
}}
 
<!-- Important concepts:
[x] Exit codes
[ ] Conditional logic
[ ] Counting / index variables
[?] Positional Parameters
[ ] Arrays
[?] Namerefs
[ ] List
[ ] section links, per syntax type
[ ] for
[ ] until
[ ] while
[ ] for ((...))
[ ] continue and break
-->
{{Blockquote
| ITERATION: Sometimes programs are repeated indefinitely or until a specific outcome is reached. Each execution of the instructions is an "iteration."<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Syracuse University]]
| title = Glossary of Coding Terms for Beginners: iteration
| url = https://onlinegrad.syracuse.edu/blog/coding-terms-for-beginners/
| website = syracuse.edu
| date = 13 January 2020
}}</ref>
| author =
| style =
}}
* {{mono|while}}, {{mono|until}}, and {{mono|select}} loop compound commands;
* Arithmetic C-style and list-enumerating {{mono|for}} loop compound commands; and
* {{mono|continue}}, {{mono|break}}, {{mono|return}}, and {{mono|exit}} flow control commands;
 
=== Compound commands ===
 
<!-- Important concepts:
[ ] Simple commands vs compound commands
[ ] List
[ ] section links, per syntax type
[ ] Grouping constructs
[ ] Functions
[ ] {...;}
[ ] (...)
[ ] Conditional constructs
[ ] Conditional logic
[ ] if
[ ] case
[ ] select
[ ] ((...))
[ ] [[...]]
[ ] Looping constructs
[ ] for
[ ] until
[ ] while
[ ] for ((...))
-->
{{Blockquote
| compound: something formed by a union of elements or parts.<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Merriam-Webster's Collegiate Dictionary]]
| title = compound - noun (1)
| url = https://www.merriam-webster.com/dictionary/compound
| website = merriam-webster.com
}}</ref>
 
| author = Merriam-Webster's Collegiate Dictionary
| style =
}}
Bash also supports {{Code| if ... fi| bash}} and {{Code| case ... esac| bash}} forms of conditional command evaluation.{{efn|concept drawn from [[ALGOL 68]];<ref name="SRB_15">
{{Cite web
| access-date = 8 August 2025
| author = Stephen R Bourne
| date = 12 June 2015
| publisher = BSDcan 2015: The Technical BSD Conference
| title = Early days of Unix and design of sh
| url = https://www.bsdcan.org/2015/schedule/attachments/306_srbBSDCan2015.pdf
| website = bsdcan.org
}}
</ref>}}
 
=== Testing ===
 
Built in commands for testing file attributes, comparing string and integer values, etc.:
* Traditional {{mono|test}} command,
* Traditional single bracket test: {{Code| [}},
* Modern double bracket test: <CODE>&#91;&#91;...&#93;&#93;</CODE>, which includes advanced features:
** Extended [[regular expression]] and extglob matching
** Lexicographic comparisons with {{Code| <}} and {{Code| >}};
* {{Code| ((...))}} numeric evaluation and testing; this includes almost all "C" language operators for arithmetic and numeric comparison;
 
For all commands the exit status is stored in the special variable {{Code| $?| bash}}.
 
=== Regular Expressions ===
 
Bash 3.0 supports in-process [[regular expression]] matching using a syntax reminiscent of [[Perl]].<ref>
{{Cite web
| access-date = 5 March 2017
| archive-date = 5 May 2017
| archive-url = https://web.archive.org/web/20170505161903/http://tldp.org/LDP/abs/html/bashver3.html#BASH3REF
| at = Section 37.2 (Bash, version 3)
| title = Advanced Bash Scripting Guide: 37.2: Bash, version 3
| url = https://www.tldp.org/LDP/abs/html/bashver3.html#BASH3REF
| url-status = live
| website = [[Linux Documentation Project]]
}}</ref>
Regexp matching is limited to strings on the right side of the <CODE>=~</CODE> operator in the {{Code| [[..]]}} extended test construct.<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = GNU Bash Manual: 3.2.5.2: Conditional Constructs
| url = https://www.gnu.org/software/bash/manual/bash.html#index-_005b_005b
| website = [[Free Software Foundation, Inc.]]
}}</ref>
 
<syntaxhighlight lang="bash" inline>[[ $line =~ [[:space:]]*(a)?b ]]</syntaxhighlight> means values for line like ‘aab’, ‘ aaaaaab’, ‘xaby’, and ‘ ab’ will all match, as will a line containing a ‘b’ anywhere in its value.
 
=== Coprocesses ===
 
<!-- Important concepts:
[ ] Job control
[ ] Keywords (ie, Reserved words)
[ ] Pipelines
[ ] Subshell
-->
{{Blockquote
| A coprocess is a shell command preceded by the coproc reserved word. A coprocess is executed asynchronously in a subshell, as if the command had been terminated with the ‘&’ control operator, with a two-way pipe established between the executing shell and the coprocess.<ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[GNU Project]]
| title = Bash Reference Manual, 3.2.6 Coprocesses
| url = https://www.gnu.org/software/bash/manual/bash.html#Coprocesses
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| author = Bash Reference Manual, 3.2.6 Coprocesses
| style =
}}
 
== Data manipulation <span class="anchor" id="Data manipulation"></span> ==
 
=== Word Splitting ===
 
Split into words (i.e., [[Text segmentation|word splitting]])
 
=== Quoting ===
 
{{Blockquote
| When in doubt -- Quote!<ref>
{{Cite book
| access-date = 16 August 2025
| date = 24 December 2015
| first = Andrew
| last = Mallett
| page = 56
| publisher = Packt Publishing, Ltd.
| quote = Learning this now can save us a lot of pain and heartache later, especially....
| title = Mastering Linux Shell Scripting
| isbn = 978-1-78439-759-3
| url = https://books.google.com/books?id=ITjlCwAAQBAJ
}}</ref>
| author = Mastering Linux Shell Scripting, by Andrew Mallett
}}
 
 
Bash has certain [[String literal|quoting]] rules: uses of
 
* single quotes {{Code|'...'| bash}}
 
* double quotes {{Code|"..."| bash}}
 
* backslashes {{Code|\| bash}}, and
 
* ANSI-C quoting {{Code| $'...'}}.
 
See also {{section link|| Locales}}, {{Code| $"..."}}
 
See also backticks {{Code| `...`}}: {{section link|| Deprecated syntax}}.
 
=== Unicode ===
 
Support for [[Unicode]] in {{Code| echo -e| bash}} and ANSI-C quoting.
 
{{Blockquote
| Unicode: international character-encoding system designed to support the electronic interchange, processing, and display of the written texts of the diverse languages of the modern and classical world.<ref>
{{Cite web
| access-date = 15 August 2025
| quote = Unicode, international character-encoding system designed to support the electronic interchange, processing, and display of the written texts of the diverse languages of the modern and classical world.
| title = Unicode
| url = https://www.britannica.com/topic/Unicode
| website = britannica.com
}}</ref>
| author = [[Encyclopædia Britannica]]
| style =
}}
 
=== Brace Expansion ===
 
:<syntaxhighlight lang = console>
$ echo kernel{,-headers}
kernel kernel-headers
</syntaxhighlight>
 
Brace expansion, also called alternation, is a feature copied from the [[C shell]].
It generates a set of alternative combinations.<ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 15 March 2018
| archive-url = https://web.archive.org/web/20180315115230/http://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.3.1 Brace Expansion
| url = https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html
| url-status = live
| website = [[Free Software Foundation, Inc.]]
}}</ref>
Generated results need not exist as files.
The results of each expanded string are not sorted and left to right order is preserved:
 
:<syntaxhighlight lang = console>
$ echo a{p,c,d,b}e
ape ace ade abe
$ echo {a,b,c}{d,e,f}
ad ae af bd be bf cd ce cf
</syntaxhighlight>
 
Users should not use brace expansions in portable shell scripts, because the [[Bourne shell]] does not produce the same output.
 
:<syntaxhighlight lang = console>
$ # bash shell
$/bin/bash -c 'echo a{p,c,d,b}e'
ape ace ade abe
$ # A traditional shell does not produce the same output
$ /bin/sh -c 'echo a{p,c,d,b}e'
a{p,c,d,b}e
</syntaxhighlight>
 
When brace expansion is combined with wildcards, the braces are expanded first, and then the resulting wildcards are substituted normally.
Hence, a listing of JPEG and PNG images in the current directory could be obtained using:
 
:<syntaxhighlight lang ="bash">
ls *.{jpg,jpeg,png} # expands to *.jpg *.jpeg *.png – after which,
# the wildcards are processed
echo *.{png,jp{e,}g} # echo just shows the expansions –
# and braces in braces are possible.
</syntaxhighlight>
 
In addition to alternation, brace expansion can be used for sequential ranges between two integers or characters separated by double dots.
Newer versions of Bash allow a third integer to specify the increment.
 
:<syntaxhighlight lang = console>
$ echo {1..10}
1 2 3 4 5 6 7 8 9 10
$ echo {01..10}
01 02 03 04 05 06 07 08 09 10
$ echo file{1..4}.txt
file1.txt file2.txt file3.txt file4.txt
$ echo {a..e}
a b c d e
$ echo {1..10..3}
1 4 7 10
$ echo {a..j..3}
a d g j
</syntaxhighlight>
 
When brace expansion is combined with variable expansion (a.k.a., ''parameter expansion'' and ''parameter substitution'') the variable expansion is performed ''after'' the brace expansion, which in some cases may necessitate the use of the {{mono|eval}} built-in, thus:
 
:<syntaxhighlight lang = console>
$ start=1; end=10
$ echo {$start..$end} # fails to expand due to the evaluation order
{1..10}
$ eval echo {$start..$end} # variable expansion occurs then resulting string is evaluated
1 2 3 4 5 6 7 8 9 10
</syntaxhighlight>
 
=== Tilde Expansion ===
{{Empty section|date=August 2025}}
 
=== Parameter and variable expansion ===
 
* Type
* Shell parameters
* Environment variables
* User variables
* Scope
* Arrays
** Indexed [[Array (data type)|arrays]]: size is unlimited.
** [[Associative array]]s: via {{Code| declare -A| bash}}{{efn|In February 2009,<ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 1 July 2018
| archive-url = https://web.archive.org/web/20180701001653/http://www.tldp.org/LDP/abs/html/bashver4.html
| title = Advanced Bash Scripting Guide: 37.3: Bash, version 4
| url = https://tldp.org/LDP/abs/html/bashver4.html
| url-status = live
| website = [[Linux Documentation Project]]
}}</ref>
Bash 4.0{{efn|Bash 4 also switches its license to [[GNU General Public License#Version 3|GPL-3.0-or-later]].
}}<ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 25 June 2018
| archive-url = https://web.archive.org/web/20180625213216/https://apple.stackexchange.com/questions/193411/update-bash-to-version-4-0-on-osx
| title = Update bash to version 4.0 on OSX
| url = https://apple.stackexchange.com/questions/193411/update-bash-to-version-4-0-on-osx
| url-status = live
| website = apple.stackexchange.com
}}</ref>
 
introduced support for [[associative arrays]].<ref name =bashfaq061/> Associative array indices are strings, in a manner similar to [[AWK]] or [[Tcl]].<ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 11 July 2018
| archive-url = https://web.archive.org/web/20180711142941/http://www.gnu.org/software/bash/manual/html_node/Arrays.html
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 6.7: Arrays
| url = https://www.gnu.org/software/bash/manual/html_node/Arrays.html
| url-status = live
| website = [[Free Software Foundation, Inc.]]
}}</ref> They can be used to emulate multidimensional arrays.}}
* Parameter Expansion
*:Expansion syntaxes which can perform some tasks more quickly than external utilities, including, among others:
** Pattern Substitution
*** {{Code| ${foo//x/y}| bash}} for <code>sed '{{codett|s/x/y/g|sed}}'</code>,
** Remove Matching Prefix or Suffix Pattern
*** {{Code| ${bar##[a-zA-Z0-9]*}| bash}} for {{Code| cut -c8-}},
** Enumerate Array Keys
*** {{Code| ${!array[@]}| bash}}, and
** Display Error if Null or Unset
*** {{Code| ${var:?error message}| bash}},
 
=== Pathname expansion ===
 
Pathname expansion, i.e., shell-style [[Glob (programming)|globbing]] and [[pattern matching]] using {{Code| *}}, {{Code| ?}}, {{Code| [...]}}.{{efn|name=brackets}}
 
=== Locales ===
 
Locale-specific translation via {{Code| $"..."| bash}} quoting syntax.<ref>
{{Cite web
| access-date = 16 August 2025
| publisher = [[Free Software Foundation]]
| quote = Prefixing a double-quoted string with a dollar sign {{Char|$}}, such as <CODE>$"hello, world"</CODE>, causes the string to be translated according to the current locale. The {{Mono| gettext}} infrastructure performs the lookup and translation, using the {{Code| $LC_MESSAGES| bash}}, {{Code| $TEXTDOMAINDIR| bash}}, and {{Code| $TEXTDOMAIN| bash}} shell variables.
| title = Bash Reference Manual, 3.1.2.5 Locale-Specific Translation
| url = https://www.gnu.org/software/bash/manual/bash.html#Locale-Translation
| website = [[Free Software Foundation, Inc.]]
}}</ref>
 
== Process redirections and parsing <span class="anchor" id="Process redirections and parsing"></span> <span class="anchor" id="Process redirections"></span> <span class="anchor" id="Parsing"></span> ==
 
=== Command substitution ===
 
[[Command substitution]]: {{Code| $(...)| bash}},
 
=== Process substitution ===
 
[[Process substitution]], {{Code| <()| bash}} or {{Code| >()| bash}}, when a system supports it:
 
Bash supports [[process substitution]] using the {{Code| <(command)| bash}} and {{Code| >(command)| bash}} syntax, which substitutes the output of (or input to) a command where a filename is normally used.
(This is implemented through ''/proc/fd/'' unnamed pipes on systems that support that, or via temporary [[named pipe]]s where necessary).
 
=== Arithmetic expansion ===
 
Arithmetic expansion, {{Code| ((...))}} or {{Code| $((...))| bash}}, including
* Integer [[arithmetic]] in any [[Radix|base]] from two to sixty-four, although
* [[Floating-point arithmetic]] is not available from within the shell itself (for this functionality, see current versions of [[Bc (programming language)| {{mono|bc}}]] and [[AWK| {{mono|awk}}]], among others),
 
Bash can perform integer calculations ("arithmetic evaluation") without spawning external processes.
It uses the {{Code| ((...))}} command and the {{Code| $((...))| bash}} variable syntax for this purpose.
 
=== Redirection ===
 
[[Redirection (computing)|Redirections]] of Standard Input, Standard Output and Standard Error [[Standard streams|data streams]] are performed, including
* File writing, {{Code| >}}, and appending, {{Code| >}},
* [[Here document]]s, {{Code| <<}},
* Here strings, {{Code| <<<}}, which allow parameters to be used as input, and
* A redirection operator, {{Code| >}}, which can force overwriting of a file when a shell's {{mono|noclobber}} setting is enabled;
 
Its syntax simplifies [[redirection (computing)|I/O redirection]].
For example, it can redirect [[standard out]]put (stdout) and [[Standard error stream|standard error]] (stderr) at the same time using the {{Code| &>| bash}} operator.
This is simpler to type than the Bourne shell equivalent '{{Code| command > file 2>&1| bash}}'.
Bash supports [[here document]]s.
Since version 2.05b Bash can redirect [[Stdin|standard input]] (stdin) from a "here string" using the {{Code| <<<}} operator.
 
=== Command parsing ===
 
*(A) Comments are ignored, from an unquoted {{Code|#}} (hash) to the end of the same line;<ref>
{{Cite web
| access-date = 15 August 2025
| title = The Bash Parser
| url = https://mywiki.wooledge.org/BashParser
| website = wooledge.org
}}</ref><ref>
{{Cite web
| access-date = 15 August 2025
| first = Chet
| last = Ramey
| title = The Architecture of Open Source Applications (Volume 1): The Bourne-Again Shell
| url = https://aosabook.org/en/v1/bash.html
| website = aosabook.org
}}</ref>
 
*(B) Commands are parsed one line at a time:
** Control structures are honored, and
** Backslash {{Code|\}} escapes are also honored at the ends of lines;
 
*(C) Split into words (i.e., [[Text segmentation|word splitting]]) according to [[String literal|quoting]] rules,
** Including ANSI-C quoting {{Code|$'...'}};
 
*(D) Seven ''types'' of expansions are performed in the following order on the resulting string:
*# ''(Type 1)'' Brace expansion <code>kernel{-headers}</code>,
*# ''(Type 2)'' Tilde expansion {{Code|~}},
*# In a left-to-right fashion:
*#* ''(Type 3)'' [[Parameter (computer programming)|Parameter]] and [[Variable (computer science)|variable]] expansion {{Code|$foo}} or {{Code|${bar}|bash}}, including
*#* ''(Type 4)'' [[Command substitution]]: {{Code|$(...)|bash}},
*#* ''(Type 5)'' [[Process substitution]], {{Code|<()|bash}} or {{Code|>()|bash}}, when a system supports it:
*#* ''(Type 6)'' Arithmetic expansion, {{Code|((...))}} or {{Code|$((...))|bash}}, including
*#** Integer [[arithmetic]] in any [[Radix|base]] from two to sixty-four, although
*#** [[Floating-point arithmetic]] is not available from within the shell itself.{{efn|for this functionality, see current versions of [[Bc (programming language)|{{Code|bc}}]] and [[AWK|{{Code|awk}}]], among others.}}
*# [[Text segmentation|Word splitting]] (again),
*# ''(Type 7)'' Pathname expansion, i.e., shell-style [[Glob (programming)|globbing]] and [[pattern matching]] using {{Code|*}}, {{Code|?}}, {{Code|[...]|bash}},{{Efn
| name = brackets
| Although they can be used in conjunction, the use of brackets in pattern matching, {{Code|[...]|bash}}, and the use of brackets in the testing commands, {{Code|[|bash}} and <CODE>&#91;&#91; ... &#93;&#93;</CODE>, are each one different things.
}}
*# [[String literal|Quote]] removal;
 
*(E) [[Redirection (computing)|Redirections]] of Standard Input, Standard Output and Standard Error [[Standard streams|data streams]] are performed, including
** File writing, {{Code|>}}, and appending, {{Code|>>}},
** [[Here document]]s, {{Code|<<}},
** Here strings, {{Code|<<<}}, which allow parameters to be used as input, and
** A redirection operator, {{Code|>}}, which can force overwriting of a file when a shell's {{Code|noclobber}} setting is enabled;
 
*(F) Command name lookup is performed, in the following order:
*# [[Command (computing)|Commands]] internal to the [[Shell (computing)|shell]]:
*#* [[Alias (command)|Shell aliases]],
*#* Shell reserved words,
*#* [[Function (computer programming)|Shell functions]], and
*#* [[Shell builtin|Shell built-in commands]];
*# Commands external to the shell:
*#* Separate [[Unix|UNIX]]-style programs such as [[ls|{{Code|ls}}]] or [[Ln (Unix)|{{Code|ln}}]], and
*#* [[Shell script]]s, which are [[File system|files]] containing executable commands.{{efn|name=script}}
 
*(G) The resulting string is executed as a command.
 
== Interactive-only features <span class="anchor" id="Interactive-only features"></span> ==
 
=== Command History ===
 
Unlimited size [[command history]].<ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 15 September 2019
| archive-url = https://web.archive.org/web/20190915123105/http://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Bash-History-Builtins
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 9.2: Bash History Builtins
| url = https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Bash-History-Builtins
| url-status = live
| website = [[Free Software Foundation, Inc.]]
}}</ref>
This feature is available in interactive mode only.
 
=== Directory stack ===
 
A directory stack ([[pushd and popd|{{Code|pushd}} and {{Code|popd}}]] built-ins) feature is available in interactive mode only.
 
=== Programmable completion ===
 
Also known as "tab completion" or "[[command-line completion]]", when a user presses the {{Keypress|[[tab key|Tab]]}}, within an interactive command-shell Bash automatically uses any available completion scripts to suggest partly typed program names, filenames and variable names.<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 8.6: Programmable Completion
| url = https://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion
| website = [[Free Software Foundation, Inc.]]
}}</ref>
<ref name =bashfaq061/>
The Bash command-line completion system is very flexible and customizable, and is often packaged with functions that complete arguments and filenames for specific programs and tasks.
 
Bash supports programmable [[Command-line completion |completion]] via built-in {{Code| complete}}, {{Code| compopt}}, and {{Code| compgen}} commands.<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[Case Western Reserve University]]
| title = Bash Reference Manual: 8.6 Programmable completion
| url = https://tiswww.case.edu/php/chet/bash/bashref.html#Programmable-Completion
| website = case.edu
}}</ref>
The feature has been available since the beta version of 2.04 released in 2000.<ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 8 March 2020
| archive-url = https://web.archive.org/web/20200308104032/http://ftp.swin.edu.au/gnu/bash/
| publisher = Swinburne University of Technology
| title = Index of /gnu/bash
| url = https://ftp.swin.edu.au/gnu/bash/
| url-status = live
| website = swin.edu.au
}}</ref>
These commands enable complex and intelligent completion specification for commands (i.e., installed programs), functions, variables, and filenames.<ref name = tldp_pc>
{{Cite web
| access-date = 21 January 2022
| title = Advanced Bash Scripting Guide: Appendix J: An Introduction to Programmable Completion
| url = https://tldp.org/LDP/abs/html/tabexpansion.html
| website = [[Linux Documentation Project]]
}}</ref>
 
The {{Code| complete}} and {{Code| compopt}} two commands specify how arguments of some available commands or options are going to be listed in the [[readline]] input.As of version 5.1 completion of the command or the option is usually activated by the {{Keypress| Tab}} keystroke after typing its name.<ref name =tldp_pc/>
This feature is available in interactive mode only.
 
=== Prompts ===
 
Configurable [[Command-line interface#Command prompt |prompts]].
This feature is available in interactive mode only.
 
=== Restricted mode ===
<!-- Note, restricted mode involves features that havent been explained yet in the Modes section -->
{{Quote
| Modern systems provide more secure ways to implement a restricted environment, such as jails, zones, or containers.<ref>
{{Cite web
| access-date = 13 August 2025
| publisher = [[GNU Project]]
| quote = Modern systems provide more secure ways to implement a restricted environment, such as jails, zones, or containers.
| title = Bash Reference Manual, 6.10 The Restricted Shell
| url = https://www.gnu.org/software/bash/manual/bash.html#The-Restricted-Shell-1
| website = [[Free Software Foundation, Inc.]]
}}</ref>
}}
 
A restricted shell is used to set up an environment more controlled than the standard shell. A restricted shell behaves identically to bash with the exception that numerous actions are disallowed or not performed, including:
 
* Changing directories with the {{code|cd}} builtin.
* Setting or unsetting the values of the {{Code| $SHELL| bash}}, {{Code| $PATH| bash}}, {{Code| $HISTFILE| bash}}, {{Code| $ENV| bash}}, or {{Code| $BASH_ENV| bash}} variables.
* Specifying command names containing slashes on the CLI.
* Using absolute pathnames as arguments to the {{Code| .}}, {{code|history}}, or {{Code| hash -p| bash}} commands
* Specifying a path search with {{Code| . -p}} or {{Code| command -p| bash}}
* Importing function definitions and parsing the value of {{Code| $SHELLOPTS| bash}} from the shell environment at startup.
* Redirecting output using the {{Code| >}}, {{Code| >}}, {{Code| <>}}, {{Code| >&}}, {{Code| &>}}, and {{Code| >>}} redirection operators.
* Using the {{code|exec}} builtin to replace the shell with another command.
* Altering shell builtins
 
Once restricted mode is enabled, it cannot be disabled. These restrictions are enforced after any startup files are read, and it does not apply to shell scripts. Restricted mode is rarely used.
 
== Documentation <span class="anchor" id="Documentation"></span> ==
 
=== User Manual ===
 
A [https://www.gnu.org/software/bash/manual/index.html user manual] for Bash is provided by the GNU Project.
It is sometimes considered to be a more user-friendly document than the man page.
"You may also find information about Bash ...by looking at {{Code| /usr/share/doc/bash}}, {{Code| /usr/local/share/doc/bash}}, or similar directories on your system."<ref name =gnu.org_bash-hm>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = Bash
| url = https://www.gnu.org/savannah-checkouts/gnu/bash/bash.html
| website = [[Free Software Foundation, Inc.]]
}}
</ref>
On GNU/Linux systems, if the {{mono|info}} program is available then the GNU Manual version relevant for your installation should also be available at {{Code| info bash}}.<ref name = gnu.org_info>
{{Cite web
| access-date = 8 August 2025
| author = [[Free Software Foundation]]
| publisher = [[GNU Project]]
| title = GNU Bash manual
| url = https://www.gnu.org/software/bash/manual/index.html
| website = [[Free Software Foundation, Inc.]]
}}
</ref><ref>
{{Cite web
{{Citation
| access-date = 8 August 2025
| last = Hamilton
| publisher = [[Case Western Reserve University]]
| first = Naomi
| title = Bash Reference Manual
| author-link = http://www.computerworld.com.au/author/97635374/naomi-hamilton/articles
| url = https://tiswww.case.edu/php/chet/bash/bashref.html
| title = The A-Z of Programming Languages: BASH/Bourne-Again Shell
| website = case.edu
| journal = Computerworld
}}</ref>
| pages = 2
 
| date = May 30, 2008
=== Man page ===
| accessdate = Mar 21, 2011
 
| url = http://www.computerworld.com.au/article/222764/a-z_programming_languages_bash_bourne-again_shell/?pp=2&fp=16&fpid=1
The most recent technical manual, or [https://tiswww.case.edu/php/chet/bash/bash.html 'man page'], is intended to be the authoritative explanatory technical document for the understanding of how bash operates.
| quote = When Richard Stallman decided to create a full replacement for the then-encumbered Unix systems, he knew that he would eventually have to have replacements for all of the common utilities, especially the standard shell, and those replacements would have to have acceptable licensing.
On GNU/Linux systems, the version relevant for your installation is usually available through the {{mono|man}} program at {{Code| man bash| bash}}.<ref name =gnu.org_info/><ref name =case.edu_bash(1)/><ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = git: index : bash.git
| url = https://git.savannah.gnu.org/cgit/bash.git/tree/doc/bash.0
| website = [[Free Software Foundation, Inc.]]
}}
</ref>
</ref> Released in 1989,<ref name=BashBeta>
 
{{Cite newsgroup
=== help builtin ===
| title = Bash is in beta release!
 
| author = Brian Fox (forwarded by Leonard H. Tower Jr.)
With recent versions of Bash, information on shell built-in commands can be found by executing {{Code| help|bash}}, {{Code| help [name of builtin]| bash}} or {{Code| man builtins}} at a terminal prompt where bash is installed.
| date = June 8, 1989
 
| newsgroup = gnu.announce
The {{mono|printf}} command can be invoked via {{mono|env}} to ensure that you run the program found via your shell's search path, and not a shell alias or built-in function: {{Code| env printf --help| bash}}.<ref>
| url = http://groups.google.com/group/gnu.announce/msg/a509f48ffb298c35?hl=en
{{cite web
| accessdate = Oct 28 2010
| access-date = 11 August 2025
| publisher = [[GNU Project]]
| title = GNU Coreutils manual v.9.7, 15.2 printf: Format and print data
| url = https://www.gnu.org/software/coreutils/manual/coreutils.html#printf_003a-Format-and-print-data
| website = [[Free Software Foundation, Inc.]]
}}</ref>
 
=== POSIX Specification ===
 
For the purpose of allowing inter-operability among different shell programs running on different operating systems, the [https://pubs.opengroup.org/onlinepubs/9799919799/ POSIX Specification] influences how modern UNIX-like shells are written.
Bash "is intended to be a conformant implementation of the IEEE POSIX ''"Shell and Utilities"'' portion of the IEEE POSIX specification (IEEE Standard 1003.1)."<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = GNU Bash Manual: 1.1: What is Bash?
| url = https://www.gnu.org/software/bash/manual/bash.html#What-is-Bash_003f
| website = [[Free Software Foundation, Inc.]]
}}
</ref>
</ref> it has been distributed widely as the shell for the [[GNU operating system]] and as the default shell on [[Linux]], {{nowrap|[[Mac OS X]]}} and [[Darwin (operating system)|Darwin]]. It has been ported to [[Microsoft Windows]] and distributed with [[Cygwin]] and [[MinGW]], to [[DOS]] by the [[DJGPP]] project and to [[Novell NetWare]].
The most recent publication of the standard (2024) is available online.<ref>
{{Cite web
| access-date = 30 July 2025
| author = Open Group
| title = POSIX 2024
| url = https://pubs.opengroup.org/onlinepubs/9799919799/
| website = [[Free Software Foundation, Inc.]]
}}
</ref>
 
As the standard upon which bash is based, the POSIX Standard, or IEEE Std 1003.1,<ref>
Bash is a [[Command-line interpreter|command processor]], typically run in a text window, allowing the user to type commands which cause actions. Bash can also read commands from a file, called a [[Shell script|script]]. Like all Unix shells, it supports filename [[Wildcard character|wildcarding]], [[Pipeline (Unix)|piping]], [[here document]]s, [[command substitution]], [[Variable (programming)|variables]] and [[control flow|control structures]] for [[Conditional (programming)|condition-testing]] and [[iteration]].<ref>
{{citeCite journalweb
| title = The Open Group Base Specifications Issue 7, 2018 edition
| last = Bourne
| url = https://pubs.opengroup.org/onlinepubs/9699919799/
| first = S.R.
| website = opengroup.org
| authorlink = Stephen R. Bourne
}}</ref>
| title = The UNIX Shell
et seq, is especially informative.
| journal = The Bell System Technical Journal
| volume = 57
| issue = 6
| pages = 1971&ndash;1990
| publisher = American Telephone and Telegraph Company
| ___location = Short Hills, NJ
| date = July/August 1978
| issn = 00005-8580
| quote = The lines between <code><<!</code> and <code>!</code> are called a ''here'' document; they are read by the shell and made available as the standard input.}}</ref> The [[Keyword (computer programming)|keywords]], [[Syntax (programming languages)|syntax]] and other basic features of the [[Language (computer science)|language]] were all copied from sh. Other features, e.g., [[C shell#History|history]], were copied from [[C shell|csh]] and [[Korn shell|ksh]]. Bash is a [[POSIX]] shell but with a number of extensions.
 
=== Further resources ===
The name itself is an [[acronym]], a [[pun]] and descriptive. As an acronym, it stands for ''Bourne-again shell'', referring to its objective as a free replacement for the Bourne shell.<ref>[http://www.ddj.com/cpp/184404693 C Programming] by Al Stevens, [[Dr. Dobb's Journal]], July 1, 2001</ref>
 
As a pun, it expressed that objective in a phrase that sounds the same as ''[[Born again (Christianity)|born again]]'', a term for spiritual rebirth.<ref>
"The project maintainer also has a Bash page which includes Frequently Asked Questions",<ref name = gnu.org_bash-hm/><ref name = bash-top>
{{Cite web
| access-date = 8 August 2025
| author = [[Richard Stallman]]
| publisher = [[Case Western Reserve University]]
| title = About the GNU Project
| title = The GNU Bourne-Again Shell, Top Page
| publisher = [[Free Software Foundation]]
| url = https://tiswww.case.edu/php/chet/bash/bashtop.html
| date = Nov 12, 2010
| website = case.edu
| url = http://www.gnu.org/gnu/thegnuproject.html
}}</ref><ref>
| quote = “Bourne Again Shell” is a play on the name “Bourne Shell”, which was the usual shell on Unix.
{{Cite web
| accessdate = Mar 13, 2011
| access-date = 8 August 2025
| publisher = [[Case Western Reserve University]]
| title = Frequently Asked Questions
| url = https://tiswww.case.edu/php/chet/bash/FAQ
| website = case.edu
}}</ref>
this FAQ is current as of bash version 5.1 and is no longer updated.
 
Informal avenues of support are available via IRC at libera.chat, in the #bash channel, and mailing lists are available at [https://www.gnu.org/software/bash/ Bash] - GNU Project - Free Software Foundation.
 
== Security and vulnerabilities <span class="anchor" id="Security and vulnerabilities"></span> <span class="anchor" id="Security"></span> <span class="anchor" id="Vulnerabilities"></span> ==
 
=== Root scripts ===
 
Running any shell scripts as the root user has, for years, been widely criticized as poor security practice.
One commonly given reason is that, when a script is executed as root, the negative effects of any bugs in a script would be magnified by root's elevated privileges.
 
One common example: a script contains the command, {{Code| rm -rf ${dir}/| bash}}, but the variable {{Code| $dir}} is left undefined.
In Linux, if the script was executed by a regular user, the shell would attempt to execute the command {{Code| rm -rf /}} as a regular user, and the command would fail.
However, if the script was executed by the root user, then the command would likely succeed and the filesystem would be erased.
 
It is recommended to use {{mono|sudo}} on a per-command basis instead.
 
=== CGI scripts ===
 
CGI scripts are a significant source of vulnerability.<ref>
{{Cite web
| access-date = 17 August 2025
| date = 23 April 2024
| publisher = Rhino Security Labs, Inc
| title = CVE-2024-2448: Authenticated Command Injection In Progress Kemp LoadMaster
| url = https://rhinosecuritylabs.com/research/cve-2024-2448-kemp-loadmaster/
| website = rhinosecuritylabs.com
}}</ref><ref>
{{Cite web
| access-date = 17 August 2025
| date = January 1999
| publisher = [[University of California, Davis]]
| title = CGI-BIN Specific Vulnerabilities
| url = https://seclab.cs.ucdavis.edu/projects/testing/papers/cgi.html
| website = ucdavis.edu
}}</ref><ref>
{{Cite web
| access-date = 17 August 2025
| archive-date = 16 April 2000
| archive-url = https://web.archive.org/web/20000416053740/http://www.lanl.gov/projects/ia/library/bits/bits0396.html
| date = March 1996
| publisher = Los Alamos National Laboratory
| title = CGI Security
| url = https://www.lanl.gov/projects/ia/library/bits/bits0396.html
| url-status = dead
| work = BITS: computing and communications news
}}</ref>
 
=== builtin {{Mono |eval}} ===
 
"The eval command is extremely powerful and extremely easy to abuse."<ref>
{{Cite web
| access-date = 17 August 2025
| archive-date = 21 July 2025
| archive-url = https://web.archive.org/web/20250721233452/http://mywiki.wooledge.org/BashFAQ/048
| title = Eval command and security issues
| url = https://mywiki.wooledge.org/BashFAQ/048
| url-status = live
| website = wooledge.org
}}</ref>
 
=== Input validation ===
 
"[[Data validation |Input validation]] is the process of ensuring data has undergone data cleansing to confirm it has data quality, that is, that it is both correct and useful."
 
{{Blockquote
| Input validation is performed to ensure only properly formed data is entering the workflow in an information system, preventing malformed data from persisting in the database and triggering malfunction of various downstream components. Input validation should happen as early as possible in the data flow, preferably as soon as the data is received from the external party.<ref>
{{Cite web
| access-date = 17 August 2025
| publisher = [[OWASP]]
| title = Input Validation Cheat Sheet
| url = https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html
| website = owasp.org
}}</ref>
| author = OWASP Input Validation Cheat Sheet
}}
 
=== Shellshock ===
 
In September 2014, a [[security bug]] was discovered<ref>
{{Cite news
| access-date = 21 June 2019
| archive-date = 21 June 2019
| archive-url = https://web.archive.org/web/20190621183753/https://www.techolac.com/linux/linux-bash-exit-status-and-how-to-set-exit-status-in-bash/
| date = 10 June 2017
| first = Cino
| last = Juliana
| title = Linux bash exit status and how to set exit status in bash - Techolac
| url = https://www.techolac.com/linux/linux-bash-exit-status-and-how-to-set-exit-status-in-bash/
| url-status = live
| website = techolac.com
}}</ref>
in the program.
It was dubbed "[[Shellshock (software bug)|Shellshock]]." Public disclosure quickly led to a range of [[Attack (computing)|attacks]] across the [[Internet]].<ref>
{{Cite web
| access-date = 25 September 2014
| archive-date = 16 October 2014
| archive-url = https://web.archive.org/web/20141016214010/http://www.theregister.co.uk/2014/09/24/bash_shell_vuln
| date = 24 September 2014
| first = John
| last = Leyden
| publisher = [[The Register]]
| title = Patch Bash NOW: 'Shell Shock' bug blasts OS X, Linux systems wide open
| url = https://www.theregister.co.uk/2014/09/24/bash_shell_vuln/
| url-status = live
| website = theregister.co.uk
}}
</ref><ref>
{{Cite news
{{Citation
| access-date = 25 September 2014
| last = Gattol
| archive-date = 5 April 2019
| first = Markus
| archive-url = https://web.archive.org/web/20190405000511/https://www.nytimes.com/2014/09/26/technology/security-experts-expect-shellshock-software-bug-to-be-significant.html
| title = Bourne-again Shell
| date = Mar25 13,September 20112014
| first = Nicole
| url = http://www.markus-gattol.name/ws/bash.html
| last = Perlroth
| quote = The name is a pun on the name of the Bourne shell (sh), an early and important Unix shell written by Stephen Bourne and distributed with Version 7 Unix circa 1978, and the concept of being "born again".
| title = Security Experts Expect 'Shellshock' Software Bug in Bash to Be Significant
| accessdate = Mar 13, 2011
| url = https://www.nytimes.com/2014/09/26/technology/security-experts-expect-shellshock-software-bug-to-be-significant.html
| url-status = live
| work = [[The New York Times]]
}}</ref><ref>
{{Cite web
| archive-date = 14 May 2016
| archive-url = https://web.archive.org/web/20160514191755/http://www.zdnet.com/article/hackers-jump-on-the-shellshock-bash-bandwagon/
| date = 29 September 2014
| first = Larry
| last = Seltzer
| publisher = [[ZDNet]]
| title = Shellshock makes Heartbleed look insignificant
| url = https://www.zdnet.com/article/shellshock-makes-heartbleed-look-insignificant/
| url-status = live
| website = zdnet.com
}}</ref>
 
Exploitation of the vulnerability could enable [[arbitrary code execution]] in [[Common Gateway Interface|CGI]] scripts executable by certain versions of Bash.
The bug involved how Bash passed function definitions to subshells through [[environment variable]]s.<ref>
{{Cite web
| access-date = 25 September 2014
| archive-date = 25 September 2014
| archive-url = https://web.archive.org/web/20140925035842/https://securityblog.redhat.com/2014/09/24/bash-specially-crafted-environment-variables-code-injection-attack/
| date = 24 September 2014
| first = Huzaifa
| last = Sidhpurwala
| publisher = [[Red Hat]]
| title = Bash specially-crafted environment variables code injection attack
| url = https://securityblog.redhat.com/2014/09/24/bash-specially-crafted-environment-variables-code-injection-attack/
| url-status = live
| website = redhat.com
}}</ref>
The bug had been present in the [[source code]] since August 1989 (version 1.03)<ref>
{{Cite web
| access-date = 4 October 2014
| archive-date = 6 October 2014
| archive-url = https://web.archive.org/web/20141006093452/http://seclists.org/oss-sec/2014/q4/102
| date = 4 October 2014
| first = Stephane
| last = Chazelas
| title = oss-sec mailing list archives
| url = https://seclists.org/oss-sec/2014/q4/102
| url-status = live
| website = seclists.org
}}</ref> and was patched in September 2014 (version 4.3).
 
Patches to fix the bugs were made available soon after the bugs were identified.
Upgrading to a current version is strongly advised.
 
It was assigned the [[Common Vulnerabilities and Exposures|Common Vulnerability]] identifiers {{CVE
| 2014-6271
| 2014-6277
| 2014-7169
| leadout=and
| link=no
}}, among others.
Under CVSS Metrics 2.x and 3.x, the bug is regarded as "high" and "critical", respectively.
 
== Deprecated syntax <span class="anchor" id="Deprecated syntax"></span> ==
{{Unreferenced section|date=August 2025}}
 
* [[Backtick]] style command substitutions: {{Code| `...`| bash}} is deprecated in favor of
** {{Code| $(...)| bash}};
* Use of {{Code| -a}} or {{Code| -o}} in {{code|test}}/{{Code| [}}/<CODE>[[</CODE> commands,
** for example, {{Code| [ -r ./file -a ! -l ./file ]|bash}} is deprecated in favor of
*** {{Code| [ -r ./file ] && ! [ -l ./file ]|bash}};
* Use of the arithmetic syntax {{Code| $[...]|bash}} is deprecated in favor of
** {{Code| $((...))| bash}} or
**{{Code| ((...))}}, as appropriate;
* Use of {{Code| ^}} as a pipeline is deprecated in favor of <CODE>|</CODE>;
* Any uses of {{mono|expr}} or {{mono|let}}.
 
== Debugging <span class="anchor" id="Debugging"></span> ==
 
=== Table of Features ===
{{sort-under}}
{| class="wikitable sortable sort-under"
|+ Bash features which can be useful during debugging.<ref name =bashfaq061/><ref name =bash-hackers.org_changes/><ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 4 November 2018
| archive-url = https://web.archive.org/web/20181104185300/http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html
| title = Advanced Bash Scripting Guide: 2.3: Debugging Bash scripts
| url = https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html
| url-status = live
| website = [[Linux Documentation Project]]
}}</ref>
 
|-
! colspan = 3 rowspan = 1 | Feature
! colspan = 1 rowspan = 2 | POSIX 2024
! colspan = 1 rowspan = 2 | Description
! colspan = 1 rowspan = 2 | Bash ver.
 
|-
! colspan = 1 rowspan = 1 | Grammar type
! colspan = 1 rowspan = 1 | Formal name
! colspan = 1 rowspan = 1 | Syntax
 
|-
| style="text-align:left" | Special Built-In Utility || set / xtrace
| style="text-align:left" | {{Code| set -x| bash}}
| {{yes}}
| style="text-align:left" | The shell's '''primary means of debugging'''.
It "writes to standard error a trace for each command after it expands the command and before it executes it."
| {{dunno}}
 
|-
| style="text-align:left" | Special Parameters || Exit Status
| style="text-align:left" | {{Code| "$?"| bash}}
| {{yes}}
| style="text-align:left" | "Expands to the shortest representation of the decimal exit status."
| {{dunno}}
 
|-
| style="text-align:left" | Parameter Expansions || Indicate Null or Unset
| style="text-align:left" | {{Code| "${parameter:?[word]}"| bash}}
| {{yes}}
| style="text-align:left" | "Where the expansion of {{Code| [word]}}, perhaps an error message or a line number, is written to standard error and the shell exits with a non-zero exit code."
| {{dunno}}
 
|-
| style="text-align:left" | Special Parameters || PID of Invoked Shell
| style="text-align:left" | {{Code| "$$"}}
| {{yes}}
| style="text-align:left" | "Expands to the shortest representation of the decimal process ID of the invoked shell."
| {{dunno}}
 
|-
| style="text-align:left" | Special Built-In Utility || set / verbose
| style="text-align:left" | {{Code| set -v| bash}}
| {{yes}}
| style="text-align:left" | "Writes its input to standard error as it is read."
| {{dunno}}
 
|-
| style="text-align:left" | Special Built-In Utility || set / pipefail
| style="text-align:left" | {{Code| set -o pipefail| bash}}
| {{yes}}
| style="text-align:left" | "Derive the exit status of a pipeline from the exit statuses of all of the commands in the pipeline, not just the last (rightmost) command."
| {{dunno}}
 
|-
| style="text-align:left" | Special Built-In Utility || set / nounset
| style="text-align:left" | {{Code| set -u| bash}}
| {{yes}}
| style="text-align:left" | When enabled, will cause the shell to exit with an error message when it encounters an unset variable expansion.
Its use has a number of counter-intuitive pitfalls.
| {{dunno}}
 
|-
| style="text-align:left" | Special Built-In Utility || set / errexit
| style="text-align:left" | {{Code| set -e| bash}}
| {{yes}}
| style="text-align:left" | Errexit is a setting that, when enabled, will, under certain very specific conditions, cause the shell to exit without an error message whenever the shell receives a non-zero exit code.
Its use is somewhat controversial, to the extent that any somewhat obscure computer program can be controversial.
Adherents claim that Errexit provides an assurance of verifiability in situations where shell scripts "must not fail." However, opponents claim that its use is unreliable, deceptively simple, highly counter-intuitive, rife with gotchas and pitfalls, and in essence "security theater." Numerous developers of Bash have strongly discouraged the use of this particular setting.
| {{dunno}}
 
|-
| style="text-align:left" | Special Built-In Utility || trap / EXIT
| style="text-align:left" | {{Code| trap '[arg]' EXIT| bash}}
| {{yes}}
| style="text-align:left" | "If a signal specifier is {{Code| 0}} or {{Code| EXIT}}, {{Code| [arg]}} is executed when the shell exits." If {{Code| [arg]}} contains expansions, then {{Code| [arg]}} should be in single quotes.
| {{dunno}}
 
|-
| style="text-align:left" | Utility || printf
| style="text-align:left" | {{Code| printf '<%s>\n' "${var}"| bash}}
| {{yes}}
| style="text-align:left" | A means of reliably printing the contents of a variable.
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || BASHPID
| style="text-align:left" | {{Code| "${BASHPID}"| bash}}
| {{no}}
| style="text-align:left" | "Expands to the process ID of the current bash process."<ref>
{{Cite web
| access-date = 8 August 2025
| id = BASHPID
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASHPID
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || BASH_ARGC
| style="text-align:left" | {{Code| "${BASH_ARGC[@]}"| bash}}
| {{no}}
| style="text-align:left" | "An array variable whose values are the number of parameters in each frame of the current bash execution call stack."<ref>
{{Cite web
| access-date = 8 August 2025
| id = BASH_ARGC
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fARGC
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || BASH_ARGV
| style="text-align:left" | {{Code| "${BASH_ARGV[@]}"| bash}}
| {{no}}
| style="text-align:left" | "An array variable containing all of the parameters in the current bash execution call stack."<ref>
{{Cite web
| access-date = 8 August 2025
| id = BASH_ARGV
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fARGV
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || BASH_LINENO
| style="text-align:left" | {{Code| "${BASH_LINENO[@]}"| bash}}
| {{no}}
| style="text-align:left" | "An array variable whose members are the line numbers in source files where each corresponding member of {{Code| "${FUNCNAME[@]}"| bash}} was invoked."<ref>
{{Cite web
| access-date = 8 August 2025
| id = BASH_LINENO
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fLINENO
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || BASH_REMATCH
| style="text-align:left" | {{Code| "${BASH_REMATCH[@]}"| bash}}
| {{no}}
| style="text-align:left" | "An array variable whose members are assigned by the <CODE>=~</CODE> binary operator to the <CODE>[[</CODE> conditional command."<ref>
{{Cite web
| access-date = 8 August 2025
| id = BASH_REMATCH
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fREMATCH
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || BASH_SOURCE
| style="text-align:left" | {{Code| "${BASH_SOURCE[@]}"| bash}}
| {{no}}
| style="text-align:left" | "An array variable whose members are the source filenames where the corresponding shell function names in the {{Code| "${FUNCNAME[@]}"| bash}} array variable are defined."<ref>
{{Cite web
| access-date = 8 August 2025
| id = BASH_SOURCE
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fSOURCE
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || BASH_XTRACEFD
| style="text-align:left" | {{Code| "${BASH_XTRACEFD}"| bash}}
| {{no}}
| style="text-align:left" | "If set to an integer corresponding to a valid file descriptor, Bash will write the trace output generated when {{Code| set -x| bash}} is enabled to that file descriptor."<ref>
{{Cite web
| access-date = 8 August 2025
| id = BASH_XTRACEFD
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fXTRACEFD
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || EPOCHREALTIME
| style="text-align:left" | {{Code| "${EPOCHREALTIME}"| bash}}
| {{no}}
| style="text-align:left" | "Each time this parameter is referenced, it expands to the number of seconds since the Unix Epoch (see {{Code| time(3)| bash}}) as a floating point value with micro-second granularity."<ref>
{{Cite web
| access-date = 8 August 2025
| id = EPOCHREALTIME
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-EPOCHREALTIME
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || FUNCNAME
| style="text-align:left" | {{Code| "${FUNCNAME[@]}"| bash}}
| {{no}}
| style="text-align:left" | "An array variable containing the names of all shell functions currently in the execution call stack."<ref>
{{Cite web
| access-date = 8 August 2025
| id = FUNCNAME
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-FUNCNAME
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || LINENO
| style="text-align:left" | {{Code| "${LINENO}"| bash}}
| {{no}}
| style="text-align:left" | "Each time this parameter is referenced, the shell substitutes a decimal number representing the current sequential line number (starting with 1) within a script or function."<ref>
{{Cite web
| access-date = 8 August 2025
| id = LINENO
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-LINENO
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || PIPESTATUS
| style="text-align:left" | {{Code| "${PIPESTATUS[@]}"| bash}}
| {{no}}
| style="text-align:left" | "An array variable containing a list of exit status values from the processes in the most-recently-executed foreground pipeline (which may contain only a single command)."<ref>
{{Cite web
| access-date = 8 August 2025
| id = PIPESTATUS
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-PIPESTATUS
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || PPID
| style="text-align:left" | {{Code| "${PPID}"| bash}}
| {{no}}
| style="text-align:left" | "The process ID of the shell's parent."<ref>
{{Cite web
| access-date = 8 August 2025
| id = PPID
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-PPID
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Bash Variables || PS4
| style="text-align:left" | {{Code| "${PS4}"| bash}}
| {{no}}
| style="text-align:left" | "The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace."<ref>
{{Cite web
| access-date = 8 August 2025
| id = PS4
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-PS4
| website = [[Free Software Foundation, Inc.]]
}}</ref>
| {{dunno}}
 
|-
| style="text-align:left" | Shell Builtin || set / restricted
| style="text-align:left" | {{Code| set -r| bash}}
| {{no}}
| style="text-align:left" | Restricted mode is intended to improve the security of an individual shell instance from a malicious human with physical access to a machine.
As threat models have changed, it has become less commonly used now than it once was.
| {{dunno}}
 
|-
| style="text-align:left" | Shell Builtin || shopt / extdebug
| style="text-align:left" | {{Code| shopt -s extdebug| bash}}
| {{no}}
| style="text-align:left" | "Behavior intended for use by debuggers."
| {{dunno}}
 
|-
| style="text-align:left" | Shell Builtin || trap / DEBUG
| style="text-align:left" | {{Code| trap '[arg]' DEBUG| bash}}
| {{no}}
| style="text-align:left" | "If a sigspec is DEBUG, the command arg is executed before" certain kinds of commands.
| {{dunno}}
 
|-
| style="text-align:left" | Shell Builtin || trap / ERR
| style="text-align:left" | {{Code| trap '[arg]' ERR| bash}}
| {{no}}
| style="text-align:left" | "If a sigspec is ERR, the command arg is executed whenever..." certain kinds of commands "return a non-zero exit status", subject to similar restrictions as with ErrExit.
| {{dunno}}
 
|-
| style="text-align:left" | Shell Builtin || trap / RETURN
| style="text-align:left" | {{Code|trap '[arg]' RETURN|bash}}
| {{no}}
| style="text-align:left" | "If a sigspec is RETURN, the command arg is executed each time a shell function or a script executed with the {{Code| .| bash}} or {{mono|source}} builtins finishes executing."
| {{dunno}}
|}
 
* Shell features specified by [[POSIX]]:
** Parameter Expansions:<ref>
{{Multiref2
|
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = GNU Bash Manual, 3.5.3: Shell Parameter Expansion
| url = https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
| website = [[Free Software Foundation, Inc.]]
}}
|
</ref> The name is also descriptive of what it did, ''bashing together'' the features of sh, [[C shell|csh]] and [[Korn shell|ksh]].<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[Case Western Reserve University]]
| title = Bash(1), Parameter Expansion
| url = https://tiswww.case.edu/php/chet/bash/bash.html#lbBB
| website = case.edu
}}
|
{{Cite web
| access-date = 18 August 2025
| publisher = [[The Open Group]]
| title = POSIX 2024, 2.6.2 Parameter Expansion
| url = https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_06_02
| website = opengroup.org
}}
}}</ref>
** Special Parameters:<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 3.4.2: Special Parameters
| url = https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html
| website = [[Free Software Foundation, Inc.]]
}}</ref><ref>
{{Cite web
| title = Shell Command Language
| url = https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_05_02
| website = opengroup.org
}}</ref>
** Special Built-In Utility {{mono|set}}:<ref name = infoandposixset>
{{Multiref2
|
{{Cite web
| access-date = 8 August 2025
| title = GNU Bash Manual, 4.3.1: The Set Builtin
| url = https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
| website = [[Free Software Foundation, Inc.]]
}}
|
{{Cite web
| title = POSIX 2024, set
| url = https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_26
| website = opengroup.org
}}
}}</ref><ref name = case.edu_bash1>
{{Cite web
| access-date = 8 August 2025
| publisher = [[Case Western Reserve University]]
| title = Bash(1), Shell builtin commands
| url = https://tiswww.case.edu/php/chet/bash/bash.html#lbDB
| website = case.edu
}}</ref>
** Special Built-In Utility {{mono|trap}}:<ref name =case.edu_bash1/><ref name = gnu.org_trap>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = Bourne Shell Builtins (Bash Reference Manual)
| url = https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html#index-trap
| website = [[Free Software Foundation, Inc.]]
}}</ref>
*** POSIX does specify certain uses of the {{mono|trap}} builtin: ...
** Utility {{mono|printf}}: a means of reliably printing the contents of a variable:
 
* Bash features not specified by POSIX:
** Bash Variables:<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html
| website = [[Free Software Foundation, Inc.]]
}}</ref><ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[Case Western Reserve University]]
| title = Bash(1), Special parameters
| url = https://tiswww.case.edu/php/chet/bash/bash.html#lbAW
| website = case.edu
}}</ref>
** Shell Builtin {{mono|set}}:<ref name =infoandposixset/><ref name =case.edu_bash1/>
** Shell Builtin {{mono|shopt}}:<ref>
{{Cite web
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| title = The Shopt Builtin (Bash Reference Manual)
| url = https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
| website = [[Free Software Foundation, Inc.]]
}}</ref><ref name =case.edu_bash1/>
** Shell Builtin {{mono|trap}}:<ref name =gnu.org_trap/><ref name =case.edu_bash1/>
*** While POSIX does specify certain uses of the {{mono|trap}} builtin, the following signal specs are Bash extensions: ...
 
* Third party debugging utilities:
** ShellCheck: Shell script analysis tool;<ref>
{{Multiref2
|
{{Cite web
| title = ShellCheck: Shell script analysis tool
| url = https://shellcheck.net
| website = shellcheck.net
}}
|
{{GitHub
| koalaman/shellcheck
| Github: shellcheck
| link = hidden
}}
}}</ref><ref name =shellcheck-1/>
** devscripts-checkbashisms: Check whether a /bin/sh script contains any common bash-specific constructs;<ref>
{{Cite web
| title = Debian -- Details of package devscripts in sid
| url = https://packages.debian.org/sid/devscripts
| website = debian.org
}}</ref><ref name =checkbashisms-1/>
** kcov: Code coverage tool without special compilation options;<ref>
{{Cite web
| title = Kcov - code coverage
| url = https://simonkagstrom.github.io/kcov
| website = github.io
}}</ref>
** Bashdb: The Bash symbolic debugger.<ref name =ref_bashdb/><ref>
{{Cite mailing list
| access-date = 8 August 2025
| publisher = [[GNU Project]]
| mailing-list = bug-bash
| title = [Bashdb-devel] Re: [PATCH] fix bashdb script handling of tmp directory
| url = https://lists.gnu.org/archive/html/bug-bash/2005-09/msg00038.html
}}</ref>
<!--
Other possibly relevant packages:
shfmt
libatf-sh
pcp-pmda-bash
pcp-pmda-shping
-->
 
==== Examples ====
 
With the {{Code| "${var:?}"| bash}} parameter expansion, an unset or null variable can halt a script.
 
:<syntaxhighlight lang = console>
$ cat ex.sh
#!/bin/bash
bar="foo is not defined"
echo "${foo:?$bar}"
echo this message doesn't print
 
$ ./ex.sh
./ex.sh: line 3: foo: foo is not defined
$
</syntaxhighlight>
 
Reliably printing the contents of an array that contains spaces and newlines first in a portable syntax, and then the same thing in Bash.
Note that POSIX doesn't have named array, only the list of arguments, {{Code| "$@"| bash}}, which can be re-set by the {{mono|set}} builtin.
 
:<syntaxhighlight lang = console>
$ # In POSIX shell:
$ set -- "a" " b" "
> c "
$ printf ',%s,\n' "$@"
,a,
, b,
,
c,
</syntaxhighlight>
 
Note that in Bash, the number of spaces before the newline is made clear.
 
:<syntaxhighlight lang = console>
$ # In Bash:
$ array=( "a" " b" "
> c " )
$ declare -p array
declare -a array=([0]="a" [1]=" b" [2]=$' \n c ')
</syntaxhighlight>
 
Printing an error message when there's a problem.
 
:<syntaxhighlight lang = console>
$ cat error.sh
#!/bin/env bash
if ! lsblk | grep sdb
then
echo Error, line "${LINENO}"
fi
$ ./error.sh
Error, line 130
</syntaxhighlight>
 
Using [[xtrace]].
If errexit had been enabled, then {{Code| echo quux| bash}} would not have been executed.
 
:<syntaxhighlight lang = console>
$ cat test.sh
#!/bin/env bash
set -x
foo=bar; echo "${foo}"
false
echo quux
$ ./test.sh
+ foo=bar
+ echo bar
bar
+ false
+ echo quux
quux
</syntaxhighlight>
 
<!-- This example from https://ru.wikipedia.org/wiki/Bash on 6 August 2025 -->
Note: {{Code| $BASHPID| bash}} differs from {{Code| $$| bash}} in certain circumstances, such as subshells that do not require bash to be reinitialized.
 
:<syntaxhighlight lang = console>
$ echo $(echo $BASHPID $$) $$ $BASHPID
25680 16920 16920 16920
# | | | |
# | | | \-- $BASHPID outside of the subshell
# | | \-- $$ outside of the subshell
# | \-- $$ inside of the subshell
# \-- $BASHPID inside of the subshell
</syntaxhighlight>
 
=== Bug reporting ===
 
{{Redirect
| bashbug
| The widely reported September 2014 bug found in Bash
| Shellshock (software bug)
}}
 
An external command called ''bashbug'' reports Bash shell bugs.
When the command is invoked, it brings up the user's default editor with a form to fill in.
The form is mailed to the Bash maintainers (or optionally to other email addresses).<ref>
{{Cite web
| archive-date = 2 October 2018
| archive-url = https://web.archive.org/web/20181002232146/https://linux.die.net/man/1/bashbug
| date = 21 October 2017
| title = bashbug(1)
| url = https://linux.die.net/man/1/bashbug
| url-status = dead
| website = die.net
}}</ref><ref>
{{Cite web
| archive-date = 6 October 2014
| archive-url = https://web.archive.org/web/20141006131347/https://developer.apple.com/library/prerelease/mac/documentation/Darwin/Reference/ManPages/man1/bashbug.1.html
| date = 4 June 2014
| title = bashbug(1) Mac OS X Manual Page
| url = https://developer.apple.com/library/prerelease/mac/documentation/Darwin/Reference/ManPages/man1/bashbug.1.html
| url-status = dead
| website = apple.com
}}</ref>
 
== History <span class="anchor" id="History"></span> ==
 
Shell script functionality originated with files called "[[RUNCOM|runcoms]]" in reference to the 1963 [[Macro (computer science)|macro]] processor of the same name.
The suffix "rc" is short for "runcom."<ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 10 June 2010
| archive-url = https://web.archive.org/web/20100610011504/http://kb.iu.edu/data/abnd.html
| date = 5 February 2009
| publisher = Indiana University
| title = In Unix, what do some obscurely named commands stand for?
| url = https://kb.iu.edu/data/abnd.htmliu.edu_09
| url-status = dead
| website = iu.edu
}}</ref>
The term [[Shell (computing)|"shell"]] was coined by Louis Pouzin in 1964 or 1965,
and appeared in his 1965 paper, "The SHELL, A Global Tool for Calling and Chaining Procedures in the System," which describes many features later found in many UNIX shells.<ref>
{{Cite web
| author = Louis Pouzin
| date = 25 November 2000
| title = The Origin of the Shell
| url = https://multicians.org/shell.html
| website = multicians.org
}}
</ref><ref>
{{Cite web
| title = The SHELL, A Global Tool for Calling and Chaining Procedures in the System
| url = https://people.csail.mit.edu/saltzer/Multics/Multics-Documents/MDN/MDN-4.pdf
| website = mit.edu
}}
</ref><ref>
{{Cite web
| access-date = 15 August 2025
| publisher = [[Encyclopædia Britannica]]
| title = Multics
| url = https://www.britannica.com/technology/Multics
| website = britannica.com
}}
</ref>
The [[ASCII]] standard for [[character encoding]] was defined in 1969 in a document called [[Request for Comments]] (RFC) 20.<ref>
{{Cite web
| access-date = 8 August 2025
| date = 16 October 1969
| first = Vint
| last = Cerf
| publisher = UCLA, Network Working Group
| title = ASCII Format for Network Interchange
| url = https://datatracker.ietf.org/doc/html/rfc20
| website = ietf.org
}}</ref>
 
 
 
=== Timeline ===
<!-- consider moving to dedicated 'Timeline of Bash' article -->
Significant events in Bash history are listed below:
 
{| class = "wikitable sortable collapsible collapsed"
! Date
! Event
 
|-
! 1988-01-10
|
[[Brian Fox (computer programmer)|Brian Fox]] began [[Computer programming|coding]] Bash after [[Richard Stallman]] became dissatisfied with the lack of progress being made by a prior developer.<ref name = comp.unix_88>
{{Cite newsgroup
| access-date = 28 December 2021
| title = at&t-free ksh (was: job control is a bug, not a feature)
| archive-date = 28 December 2021
| author = Ian Darwin
| archive-url = https://web.archive.org/web/20211228023030/https://groups.google.com/g/comp.unix.questions/c/iNjWwkyroR8/m/yedr9yDWSuQJ
| date = June 13, 1989
| date = 10 February 1988
| newsgroup = comp.os.minix
| last1 = Stallman
| id =
| first1 = Richard
| url = http://groups.google.com/group/comp.os.minix/msg/63c036d82ceca4d6?hl=en
| last2 = Ramey
| accessdate = Mar 21, 2011
| first2 = Chet
| quote = Yup, the gnu project's Born Again Shell ("bash") is an attempt at bashing all the features of sh together with many of those from both csh and ksh.
| message-id = 2362@mandrill.CWRU.Edu
| newsgroup = comp.unix.questions
| quote = For a year and a half, the GNU shell was "just about done". The author made repeated promises to deliver what he had done, and never kept them. Finally I could no longer believe he would ever deliver anything. So Foundation staff member Brian Fox is now implementing an imitation of the Bourne shell.
| title = GNU + BSD = ?
| url = https://groups.google.com/g/comp.unix.questions/c/iNjWwkyroR8/m/yedr9yDWSuQJ
| url-status = live
| website = google.com
}}
</ref>
Stallman and the [[Free Software Foundation|FSF]] considered a free shell that could run existing shell scripts so strategic to a completely free system built from BSD and GNU code that this was one of the few projects they funded themselves.
Fox undertook the work as an employee of FSF.<ref name =comp.unix_88/><ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 24 April 2011
| archive-url = https://web.archive.org/web/20110424064815/https://www.gnu.org/gnu/thegnuproject.html
| date = 3 October 2010
| first = Richard
| last = Stallman
| publisher = [[GNU Project]]
| quote = Free Software Foundation employees have written and maintained a number of GNU software packages. Two notable ones are the C library and the shell. ... We funded development of these programs because the GNU Project was not just about tools or a development environment. Our goal was a complete operating system, and these programs were needed for that goal.
| title = About the GNU Project
| url = https://www.gnu.org/gnu/thegnuproject.html
| url-status = live
| website = [[Free Software Foundation, Inc.]]
 
}}
== History ==
</ref>
Brian Fox began [[Computer programming|coding]] Bash on January 10, 1988<ref>
 
{{Citation
|-
| author = Brian Fox
! 1989-06-08
| title = shell.c
|
| place =
Fox released Bash as a beta, version 0.99.<ref>
| publisher = [[Free Software Foundation]]
{{Cite newsgroup
| date = August 29, 1996
| access-date = 28 October 2010
| url = http://ftp.gnu.org/gnu/bash/bash-1.14.7.tar.gz
| archive-date = 4 May 2013
| quote = Birthdate: Sunday, January 10th, 1988. Initial author: Brian Fox
| archive-url = https://web.archive.org/web/20130504075535/http://groups.google.com/group/gnu.announce/msg/a509f48ffb298c35?hl=en
}}
| date = 8 June 1989
</ref> after [[Richard Stallman]] became dissatisfied with the lack of progress being made by a prior developer.<ref name=GNUBSD/> Stallman and the [[Free Software Foundation]] (FSF) considered a free shell that could run existing sh scripts so strategic to a completely free system built from BSD and GNU code that this was one of the few projects they funded themselves, with Fox undertaking the work as an employee of FSF.<ref name=GNUBSD/><ref>
| first1 = Brian
| first2 = Leonard H.
| last1 = Fox
| last2 = Tower Jr.
| newsgroup = gnu.announce
| title = Bash is in beta release!
| url = https://groups.google.com/group/gnu.announce/msg/a509f48ffb298c35?hl=en
| url-status = live
| website = google.com
}}</ref>
The license was GPL-1.0-or-later.
"In addition to supporting backward-compatibility for scripting, Bash has incorporated features from the Korn and C shells.
You'll find command history, command-line editing, a directory stack (pushd and popd), many useful environment variables, command completion, and more."<ref>
{{Cite web
| date = 9 December 2011
| author = [[Richard Stallman]]
| publisher = IBM
| title = About the GNU Project
| title = Evolution of shells in Linux
| publisher = [[Free Software Foundation]]
| url = https://developer.ibm.com/tutorials/l-linux-shells/
| date = October 3, 2010
| website = ibm.com
| url = http://www.gnu.org/gnu/thegnuproject.html
| accessdate = Mar 21, 2011
| quote = Free Software Foundation employees have written and maintained a number of GNU software packages. Two notable ones are the C library and the shell. ... We funded development of these programs because the GNU Project was not just about tools or a development environment. Our goal was a complete operating system, and these programs were needed for that goal.
}}
</ref>
</ref> Fox released Bash as a beta, version .99, on June 7, 1989<ref name=BashBeta/> and remained the primary maintainer until sometime between mid-1992<ref>
Eventually it supported "regular expressions (similar to Perl), and associative arrays".
 
|-
! 1991
|
Bash holds historical significance as one of the earliest programs ported to Linux by [[Linus Torvalds]], alongside the GNU Compiler ([[GNU Compiler Collection|GCC]]).<ref>
{{Cite newsgroup
| access-date = 8 August 2025
| title = January 1993 GNU's Bulletin
| date = 26 August 1991
| author = len (g...@prep.ai.mit.edu)
| first = Linus
| date = April 20, 1993
| last = Torvalds
| newsgroup = gnu.announce
| newsgroup = comp.os.minix
| id = gnusenet930421bulletin@prep.ai.mit.edu
| quote = To make things really clear - yes I can run gcc on it, and bash, and most of the gnu [bin/file]utilities
| url = http://groups.google.com/group/gnu.misc.discuss/msg/4f42c739cd7e8bd8
| title = What would you like to see most in Minix?
| accessdate = Oct 28 2010
| url = https://groups.google.com/group/comp.os.minix/msg/b813d52cbc5a044b
| website = google.com
}}</ref>
 
|-
! 1992 ~ 1994
|
Brian Fox retired as the primary maintainer sometime between mid-1992 <ref>
{{Cite newsgroup
| access-date = 28 October 2010
| archive-date = 2 March 2021
| archive-url = https://web.archive.org/web/20210302213455/https://groups.google.com/forum/
| date = 20 April 1993
| message-id = gnusenet930421bulletin@prep.ai.mit.edu
| newsgroup = gnu.announce
| title = January 1993 GNU's Bulletin
| url = https://groups.google.com/group/gnu.misc.discuss/msg/4f42c739cd7e8bd8
| url-status = live
| website = google.com
}}
</ref>
</ref> and mid-1994,<ref name="Bourne shell grammar">{{cite web|first=Chet|last=Ramey|title=Bash - the GNU shell (Reflections and Lessons Learned)|url=http://www.linuxjournal.com/article/2800#N0xa50890.0xb46380|accessdate=2008-11-13| date=1994-08-01|work=[[Linux Journal]]}}</ref> when he was laid off from FSF<ref>
and mid-1994.<ref>
{{Cite web
| access-date = 13 November 2008
| archive-date = 5 December 2008
| archive-url = https://web.archive.org/web/20081205082152/http://www.linuxjournal.com/article/2800
| date = 1 August 1994
| first = Chet
| last = Ramey
| publisher = [[Linux Journal]]
| title = Bash – the GNU shell (Reflections and Lessons Learned)
| url = https://www.linuxjournal.com/article/2800#N0xa50890.0xb46380
| url-status = live
| website = linuxjournal.com
}}
</ref><ref>
{{Citation
| access-date = 31 October 2010
| title = Dates in your Computerworld interview
| archive-date = 20 July 2012
| author = Chet Ramey
| archive-url = https://web.archive.org/web/20120720124341/http://www.scribd.com/doc/40556434/2010-10-31-Chet-Ramey-Early-Bash-Dates
| date = October 31, 2010
| date = 31 October 2010
| url = http://www.scribd.com/doc/40556434/2010-10-31-Chet-Ramey-Early-Bash-Dates
| first = Chet
| accessdate = Oct 31 2010
| last = Ramey
| title = Dates in your Computerworld interview
| url = https://www.scribd.com/doc/40556434/2010-10-31-Chet-Ramey-Early-Bash-Dates
| url-status = live
| website = scribd.com
}}
</ref>
</ref> and his responsibility was transitioned to another early contributor, Chet Ramey.<ref>
His responsibility was transitioned to another early contributor, Chet Ramey.<ref name =bash-top/><ref>
{{Multiref2
|
{{Cite newsgroup
| access-date = 1 November 2010
| title = Bash 0.99 fixes & improvements
| archive-date = 10 November 2012
| author = Chet Ramey
| archive-url = https://web.archive.org/web/20121110194014/http://groups.google.com/group/gnu.bash.bug/msg/1fc7b688f5d44438?hl=en
| date = June 12, 1989
| date = 12 June 1989
| newsgroup = gnu.bash.bug
| last = Ramey
| id =
| first = Chet
| url = http://groups.google.com/group/gnu.bash.bug/msg/1fc7b688f5d44438?hl=en
| newsgroup = gnu.bash.bug
| accessdate = Nov 1 2010
| title = Bash 0.99 fixes & improvements
| url = https://groups.google.com/group/gnu.bash.bug/msg/1fc7b688f5d44438?hl=en
| url-status = live
| website = google.com
}}
|
</ref><ref>
{{Cite newsgroup
| access-date = 30 October 2010
| title = Some bash-1.02 fixes
| archive-date = 10 November 2012
| author = Chet Ramey
| archive-url = https://web.archive.org/web/20121110194034/http://groups.google.com/group/gnu.bash.bug/msg/072a03645663caea?hl=en
| date = July 24, 1989
| date = 24 July 1989
| newsgroup = gnu.bash.bug
| last = Ramey
| id =
| first = Chet
| url = http://groups.google.com/group/gnu.bash.bug/msg/072a03645663caea?hl=en
| newsgroup = gnu.bash.bug
| accessdate = Oct 30 2010
| title = Some bash-1.02 fixes
| url = https://groups.google.com/group/gnu.bash.bug/msg/072a03645663caea?hl=en
| url-status = live
| website = google.com
}}
|
</ref><ref>
{{Cite newsgroup
| access-date = 30 October 2010
| title = Availability of bash 1.05
| archive-date = 10 November 2012
| author = Brian Fox
| archive-url = https://web.archive.org/web/20121110194052/http://groups.google.com/group/gnu.bash.bug/msg/e6112ccc8866e2f4?hl=en
| date = March 2, 1990
| date = 2 March 1990
| newsgroup = gnu.bash.bug
| last | id = Fox
| first = Brian
| url = http://groups.google.com/group/gnu.bash.bug/msg/e6112ccc8866e2f4?hl=en
| newsgroup = gnu.bash.bug
| accessdate = Oct 30 2010
| title = Availability of bash 1.05
| url = https://groups.google.com/group/gnu.bash.bug/msg/e6112ccc8866e2f4?hl=en
| url-status = live
| website = google.com
}}
}}</ref><ref name =computerworld_08/><ref name =goftw2015/>
Since then, Bash has become the most popular default interactive shell among the major GNU/Linux distributions, such as [[Fedora Linux|Fedora]], [[Debian]], and [[openSUSE]], as well as among their derivatives and competitors.<ref>
{{Cite book
| access-date = 6 June 2016
| archive-date = 2 March 2021
| archive-url = https://web.archive.org/web/20210302212409/https://books.google.com/books?id=2P3zBgAAQBAJ&q=%22most+popular%22+linux+shell&pg=PA5
| date = April 2015
| edition = 3rd
| first1 = Christine
| first2 = Richard
| isbn = 978-1-119-02122-3
| last1 = Bresnahan
| last2 = Blum
| page = 5
| publisher = John Wiley & Sons, Inc.
| quote = In Linux, most users run bash because it is the most popular shell.
| title = CompTIA Linux+ Powered by Linux Professional Institute Study Guide: Exam LX0-103 and Exam LX0-104
| url = https://books.google.com/books?id=2P3zBgAAQBAJ&q=%22most+popular%22+linux+shell&pg=PA5
| url-status = live
}}
</ref><ref>
{{Cite book
| access-date = 6 June 2016
| archive-date = 2 March 2021
| archive-url = https://web.archive.org/web/20210302212410/https://books.google.com/books?id=tIjrVYbZmUAC&q=bash+most+popular+unix+shell&pg=PA363
| date = February 2006
| first1 = Arman
| first2 = Michael
| isbn = 978-0-7821-5277-7
| last1 = Danesh
| last2 = Jang
| page = 363
| publisher = John Wiley & Sons, Inc.
| quote = The Bourne Again Shell (bash) is the most common shell installed with Linux distributions.
| title = Mastering Linux
| url = https://books.google.com/books?id=tIjrVYbZmUAC&q=bash+most+popular+unix+shell&pg=PA363
| url-status = live
}}
</ref>
 
|-
==Features==
! 1994-01-26
The Bash [[command (computing)|command]] syntax is a [[superset]] of the Bourne shell command syntax. The vast majority of Bourne shell scripts can be executed by Bash without modification, with the exception of Bourne shell scripts stumbling into fringe syntax behavior interpreted differently in Bash or attempting to run a system command matching a newer Bash builtin, etc. Bash command syntax includes ideas drawn from the [[Korn shell]] (ksh) and the [[C shell]] (csh) such as command line editing, [[command history]], the directory stack, the <tt>$RANDOM</tt> and <tt>$PPID</tt> variables, and POSIX [[command substitution]] syntax <tt>$(…)</tt>. When used as an interactive command shell and pressing the [[tab key]], Bash automatically uses [[command line completion]] to match partly typed program names, filenames and variable names. The Bash command-line completion system is very flexible and customizable, and is often packaged with functions that complete arguments and filenames for specific programs and tasks.
|
Debian – initial release.
Bash is the default interactive and non-interactive shell.<ref name = debian.org_shell>
{{Cite web
| title = Debian Wiki: Shell
| url = https://wiki.debian.org/Shell
| website = debian.org
}}</ref>
 
|-
Bash's syntax has many extensions which the Bourne shell lacks. Bash can perform integer calculations without spawning external processes, unlike the Bourne shell. Bash uses the <tt>((…))</tt> command and the <tt>$((…))</tt> variable syntax for this purpose. Bash syntax simplifies [[redirection (computing)|I/O redirection]] in ways that are not possible in the traditional Bourne shell. For example, Bash can redirect [[standard streams#Standard output (stdout)|standard output]] (stdout) and [[standard streams#Standard error (stderr)|standard error]] (stderr) at the same time using the <tt>&></tt> operator. This is simpler to type than the Bourne shell equivalent '<tt>command > file 2>&1</tt>'. Bash supports [[process substitution]] using the <tt><(command)</tt> syntax, which substitutes the output of (or input to) a command where a filename is normally used.
! 1996-12-31
|
Chet Ramey released bash 2.0.
The license was GPL-2.0-or-later
 
|-
When using the 'function' keyword, Bash function declarations are not compatible with Bourne/Korn/POSIX scripts (the Korn shell has the same problem when using 'function'), but Bash accepts the same function declaration syntax as the Bourne and Korn shells, and is POSIX conformant. Due to these and other differences, Bash shell scripts are rarely runnable under the Bourne or Korn shell interpreters unless deliberately written with that compatibility in mind, which is becoming less common as Linux becomes more widespread. But in POSIX mode,<ref name="GNUBASHREF">
! 1997-06-05
{{Citation
|
| title = The GNU Bash Reference Manual, for Bash, Version 4.1
Bash 2.01 released.
| place =
| publisher =
| origyear =
| date = December 23, 2009
| volume =
| edition =
| chapter = 6.11 Bash POSIX Mode
| chapterurl = http://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html
| accessdate = Oct 26 2010
 
|-
| url = http://www.gnu.org/software/bash/manual/html_node/index.html
! 1998-04-18
|
Bash 2.02 released.
 
|-
! 1999-02-19
|
Bash 2.03 released.
 
|-
! 2000-03-21
|
Bash 2.04 released.
 
|-
! 2000-09-14
|
Bug-bash mailing list exists.<ref>
{{Cite mailing list
| access-date = 8 August 2025
| date = 14 September 2000
| first = Chet
| last = Ramey
| mailing-list = bug-bash
| publisher = [[GNU Project]]
| title = Re: Line-Edit mode is lost if "set -o vi" is in any files sourced on login.
| url = https://lists.gnu.org/archive/html/bug-bash/2000-09/msg00000.html
}}
</ref>
</ref> Bash conformance with POSIX is nearly perfect.
 
|-
Bash supports [[here document]]s just as the Bourne shell always has. In addition, since version 2.05b Bash can redirect [[standard streams#Standard input (stdin)|standard input]] (stdin) from a "here string" using the <tt><<<</tt> operator.
! 2001-04-09
|
Bash 2.05 released.<ref>
{{Cite mailing list
| access-date = 8 August 2025
| date = 9 April 2001
| first = Chet
| last = Ramey
| mailing-list = bug-bash
| publisher = [[GNU Project]]
| title = Bash-2.05 available for FTP
| url = https://lists.gnu.org/archive/html/bug-bash/2001-04/msg00047.html
}}
</ref>
 
|-
Bash 3.0 supports in-process [[regular expression]] matching using a syntax reminiscent of [[Perl]].<ref>The syntax matches that shown on the <code>[http://www.tin.org/bin/man.cgi?section=7&topic=regex regex(7)]</code> [[man page]].</ref>
! 2003
|
<!--- To do: unformatted citation: "Essential_Mac_OS_X_Panther" --->
Bash became the default shell on Apple's operating systems (i.e., MacOS) starting with OS X 10.3 Panther.<ref>[https://www.google.com/books/edition/Essential_Mac_OS_X_Panther_Server_Admini/zrI-U0KWj3cC?hl=en&gbpv=1&dq=bash&pg=PA189&printsec=frontcover Essential Mac OS S Panther Server Administration, pg 189]
</ref><ref>
{{Cite book
| access-date = 8 August 2025
| archive-date = 2 March 2021
| archive-url = https://web.archive.org/web/20210302212410/https://books.google.com/books?id=dwIRERUpQPEC&q=bash+most+popular+unix+shell&pg=PA6
| date = April 2005
| first1 = Eric
| first2 = John C.
| first3 = Micah
| isbn = 978-0-7645-9791-6
| last1 = Foster-Johnson
| last2 = Welch
| last3 = Anderson
| page = 6
| publisher = John Wiley & Sons, Inc.
| quote = Bash is by far the most popular shell and forms the default shell on Linux and Mac OSX systems.
| title = Beginning Shell Scripting
| url = https://books.google.com/books?id=dwIRERUpQPEC&q=bash+most+popular+unix+shell&pg=PA6
| url-status = live
}}
</ref>
It was available on OS X 10.2 Jaguar as well where the default shell was tcsh.
 
|-
Bash 4 introduced support for associative arrays.<ref name=GNUBASHREF/><ref>"The shell provides associative array variables, with the appropriate support to create, delete, assign values to, and expand them." http://tiswww.case.edu/php/chet/bash/NEWS</ref> Associative arrays allow a fake support for multi-dimensional (indexed) arrays, in a similar way to [[AWK]]:
! 2004-07-27
|
Bash 3.0 released.<ref>
{{Cite mailing list
| access-date = 8 August 2025
| mailing-list = bug-bash
| publisher = [[GNU Project]]
| title = Bash-3.0 available for FTP
| url = https://lists.gnu.org/archive/html/bug-bash/2004-07/msg00255.html
}}
</ref>
 
|-
<source lang="bash">
! 2005-12-09
declare -A a # declare an associative array 'a' faking a bi-dimensional indexed array
|
i=1; j=2 # initialize some indices
Bash 3.1 released.<ref>
a[$i,$j]=5 # associate value "5" to key "$i,$j" (i.e. "1,2")
{{Cite mailing list
echo ${a[$i,$j]} # print the stored value at key "$i,$j"
| access-date = 8 August 2025
</source>
| mailing-list = bug-bash
| publisher = [[GNU Project]]
| title = Bash-3.1 released
| url = https://lists.gnu.org/archive/html/bug-bash/2005-12/msg00018.html
}}
</ref>
 
|-
===Brace expansion===
! 2006-10-12
|
Bash 3.2 released.<ref>
{{Cite mailing list
| access-date = 8 August 2025
| mailing-list = bug-bash
| publisher = [[GNU Project]]
| title = Bash-3.2 available for FTP
| url = https://lists.gnu.org/archive/html/bug-bash/2006-10/msg00057.html
}}
</ref>
The license was GPL-2.0-or-later.
 
|-
Brace expansion, also called alternation, is a feature copied from the [[C shell]] that generates a set of alternative combinations. The generated results need not exist as files. The results of each expanded string are not sorted and left to right order is preserved:
! 2006
|
Ubuntu replace bash with dash as its default shell.
 
|-
<source lang="bash">
! 2009-02-20
echo a{p,c,d,b}e # ape ace ade abe
|
echo {a,b,c}{d,e,f} # ad ae af bd be bf cd ce cf
Bash 4.0 released<ref>
</source>
{{Cite mailing list
Brace expansions should not be used in portable shell scripts, because the Bourne shell will not produce the same output.
| access-date = 8 August 2025
| mailing-list = bug-bash
| publisher = [[GNU Project]]
| title = Bash-4.0 available for FTP
| url = https://lists.gnu.org/archive/html/bug-bash/2009-02/msg00164.html
}}
</ref>
Its license is GPL-3.0-or-later.
 
|-
<source lang="bash">
! 2010-01-02
#!/bin/sh
|
Bash 4.1 released.<ref>
{{Cite mailing list
| access-date = 8 August 2025
| mailing-list = bug-bash
| publisher = [[GNU Project]]
| title = Bash-4.1 available for FTP
| url = https://lists.gnu.org/archive/html/bug-bash/2010-01/msg00000.html
}}
</ref>
 
|-
# A traditional shell does not produce the same output
! 2011-02-14
echo a{p,c,d,b}e # a{p,c,d,b}e
|
</source>
Bash 4.2 released.<ref>
{{Cite mailing list
| access-date = 8 August 2025
| mailing-list = bug-bash
| publisher = [[GNU Project]]
| title = Bash-4.2 available for FTP
| url = https://lists.gnu.org/archive/html/bug-bash/2011-02/msg00134.html
}}
</ref>
 
|-
When brace expansion is combined with wildcards, the braces are expanded first, and then the resulting wildcards are substituted normally. Hence, a listing of JPEG and PNG images in the current directory could be obtained with:
! 2012
|
On [[Solaris (operating system)|Solaris]] 11, "the default user shell is the Bourne-again (bash) shell."<ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 12 June 2018
| archive-url = https://web.archive.org/web/20180612144748/https://docs.oracle.com/cd/E23824_01/html/E24456/userenv-1.html
| publisher = [[Oracle Corporation]]
| title = User Environment Feature Changes
| url = https://docs.oracle.com/cd/E23824_01/html/E24456/userenv-1.html
| url-status = live
| website = oracle.com
}}
</ref>
 
|-
<source lang="bash">
! 2014-02-27
ls *.{jpg,jpeg,png} # expands to *.jpg *.jpeg *.png - after which,
|
# the wildcards are processed
Bash 4.3 released.<ref>
</source>
{{Cite mailing list
| access-date = 8 August 2025
| mailing-list = bug-bash
| publisher = [[GNU Project]]
| title = Bash-4.3 available for FTP
| url = https://lists.gnu.org/archive/html/bug-bash/2014-02/msg00081.html
}}
</ref>
 
|-
===Startup scripts===
!2014-09-08
When Bash starts, it executes the commands in a variety of different scripts.
|
[[Shellshock (software bug)]].<ref>
{{Cite web
| access-date = 8 August 2025
| quote = GNU Bash through 4.3 processes trailing strings after function definitions in the values of environment variables, which allows remote attackers to execute arbitrary code via a crafted environment, as demonstrated by vectors involving the ForceCommand feature in OpenSSH sshd, the mod_cgi and mod_cgid modules in the Apache HTTP Server, scripts executed by unspecified DHCP clients, and other situations in which setting the environment occurs across a privilege boundary from Bash execution, aka "ShellShock."
| title = CVE-2014-6271
| url = https://www.cve.org/CVERecord?id=CVE-2014-6271
| website = cve.org
}}
</ref><ref>
{{Cite web
| access-date = 8 August 2025
| title = CVE-2014-7169
| url = https://www.cve.org/CVERecord?id=CVE-2014-7169
| website = cve.org
}}
</ref>
Patches to fix the bugs were made available soon after the bugs were identified.<ref>
{{Cite mailing list
| access-date = 8 August 2025
| mailing-list = bug-bash
| publisher = [[GNU Project]]
| title = Bash 3.0 Official Patch 1
| url = https://lists.gnu.org/archive/html/bug-bash/2004-09/msg00083.html
}}
</ref>
 
|-
<!-- A little margin for readability -->
! 2015
<div style="margin: 1.5em 3em">
|
'''When started as an interactive login shell:'''
[[Termux]] and other terminal emulation applications provide availability of Bash on [[Android (operating system)|Android]].
* Bash reads and executes the <tt>/etc/profile</tt> (if it exists).
* After reading that file, it looks for <tt>~/.bash_profile</tt>, <tt>~/.bash_login</tt>, and <tt>~/.profile</tt> ''in that order'', and reads and executes the first one (that exists and is readable).
 
|-
'''When a login shell exits:'''
! 2016-09-15
* Bash reads and executes <tt>~/.bash_logout</tt> (if it exists).
|
Bash 4.4 released.
 
|-
'''When started as an interactive shell (but not a login shell):'''
! 2009 ~ 2018
* Bash reads and executes <tt>~/.bashrc</tt> (if it exists). This may be inhibited by using the <tt>--norc</tt> option. The <tt>--rcfile file</tt> option will force Bash to read and execute commands from <tt>file</tt> instead of <tt>~/.bashrc</tt>.
|
</div>
Apple declines to accept version 4 of Bash being licensed under version 3 of the [[GNU GPL]], and ceases to supply upgrades to Bash beyond version 3.2 (as supplied in [[MacOS Mojave]]).
 
|-
===Portability===
! 2019-06-05
Invoking Bash with the <code>--posix</code> option or stating <code>set -o posix</code> in a script causes Bash to conform very closely to the [[Posix#POSIX.2|POSIX 1003.2 standard]].<ref name=tldp />
|
Bash shell scripts intended for [[portability (computer science)|portability]] should at least take into account the Bourne shell it intends to replace.
Apple declares [[Z Shell|zsh]] its default shell<ref>
Bash has certain features that the traditional Bourne shell lacks. Among these are<ref name=tldp>{{cite web|author=Mendel Cooper|title=Portability Issues|url=http://tldp.org/LDP/abs/html/portabilityissues.html|work=The Linux Documentation Project|publisher=ibiblio.org}}</ref>:
{{Cite web
*Certain extended invocation options
| access-date = 8 August 2025
*Command substitution using $( ) notation (this feature is part of the POSIX 1003.2 standard though)
| date = 5 June 2019
*Brace expansion
| first = Armin
*Certain array operations, and associative arrays
| last = Briegel
*The double brackets extended test construct
| title = Moving to zsh
*The double-parentheses arithmetic-evaluation construct
| url = https://scriptingosx.com/2019/06/moving-to-zsh/?form=MG0AV3
*Certain string manipulation operations
| website = scriptingosx.com
*Process substitution
}}
*A Regular Expression matching operator
</ref>
*Bash-specific builtins
and supplies version 5.7 in its [[MacOS Catalina|Catalina]] release of MacOS.<ref>
*Coprocesses
{{Cite web
| access-date = 8 August 2025
| archive-date = 2 December 2019
| archive-url = https://web.archive.org/web/20191202143802/https://support.apple.com/en-us/HT208050
| title = Apple Support – Use zsh as the default shell on your Mac
| url = https://support.apple.com/en-us/HT208050
| url-status = live
| website = apple.com
}}
</ref><ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 10 June 2019
| archive-url = https://web.archive.org/web/20190610051842/https://www.theverge.com/2019/6/4/18651872/apple-macos-catalina-zsh-bash-shell-replacement-features
| date = 4 June 2019
| first = Tom
| last = Warren
| publisher = [[The Verge]]
| quote = The bash binary bundled with macOS has been stuck on version 3.2 for a long time now. Bash v4 was released in 2009 and bash v5 in January 2019. The reason Apple has not switched to these newer versions is that they are licensed with GPL v3. Bash v3 is still GPL v2.
| title = Apple replaces bash with zsh as the default shell in macOS Catalina
| url = https://www.theverge.com/2019/6/4/18651872/apple-macos-catalina-zsh-bash-shell-replacement-features
| url-status = live
| website = theverge.com
}}
</ref><ref>
{{Cite web
| access-date = 8 August 2025
| archive-date = 31 December 2020
| archive-url = https://web.archive.org/web/20201231231721/https://thenextweb.com/dd/2019/06/04/why-does-macos-catalina-use-zsh-instead-of-bash-licensing/
| date = 4 June 2019
| first = Matthew
| language = en-us
| last = Hughes
| website = [[TNW (website) |The Next Web]]
| title = Why does macOS Catalina use Zsh instead of Bash? Licensing
| url = https://thenextweb.com/dd/2019/06/04/why-does-macos-catalina-use-zsh-instead-of-bash-licensing/
| url-status = live
}}
</ref>
 
|-
===Keyboard shortcuts===
! 2019-01-07
The following shortcuts work when using default ([[Emacs]]) key bindings. [[Vim (text editor)|Vi]]-bindings can be enabled by running <code>set -o vi</code>.<ref>http://www.hypexr.org/bash_tutorial.php#emacs</ref>
|
Bash 5.0 released.<ref>
{{Cite mailing list
| access-date = 8 August 2025
| mailing-list = bug-bash
| publisher = [[GNU Project]]
| title = Bash-5.0 release available
| url = https://lists.gnu.org/archive/html/bug-bash/2019-01/msg00063.html
}}
</ref>
 
|-
Note: For shortcuts involving {{key press|Alt}}, you may be able to use {{key press|Esc}} instead.
! 2020-12-07
|
Bash 5.1 released.<ref>
{{Cite mailing list
| access-date = 8 August 2025
| mailing-list = bug-bash
| publisher = [[GNU Project]]
| title = Bash-5.1 release available
| url = https://lists.gnu.org/archive/html/bug-bash/2020-12/msg00002.html
}}
</ref>
 
|-
Note: Sometimes, you must use {{key press|Esc}} instead of {{key press|Alt}}, because the {{key press|Alt}} shortcut conflicts with another shortcut. For example, in [[Trisquel|Trisquel 5.0]] (a distribution of Linux), pressing {{key press|Alt|f}} will not move the cursor forward one word, but will activate "File" in the menu of the terminal window.
! 2022-09-26
|
Bash 5.2 released.
 
|-
{{See also|Readline}}
! 2025
|
Bash 5.3 released.
 
|}
* {{key press|TAB}} : [[Autocomplete]]s from the cursor position.
* {{key press|Ctrl|a}} : Moves the cursor to the line start (equivalent to the key {{key press|[[home key|Home]]}}).
* {{key press|Ctrl|b}} : Moves the cursor back one character (equivalent to the key {{key press|[[arrow keys|Left]]}}).
* {{key press|Ctrl|c}} : Sends the signal [[SIGINT (POSIX)|SIGINT]] to the current task, which aborts and closes it.
* {{key press|Ctrl|d}}
** Sends an EOF marker, which (unless disabled by an option) closes the current [[shell (computing)|shell]] (equivalent to the command <code>[[exit (command)|exit]]</code>). (Only if there is no text on the current line)
** If there is text on the current line, deletes the current character (then equivalent to the key {{key press|[[Delete key|Delete]]}}).
* {{key press|Ctrl|e}} : ([[wikt:end|end]]) moves the cursor to the line end (equivalent to the key {{key press|[[end key|End]]}}).
* {{key press|Ctrl|f}} : Moves the cursor forward one character (equivalent to the key {{key press|[[arrow keys|Right]]}}).
* {{key press|Ctrl|g}} : Abort the research and restore the original line.
* {{key press|Ctrl|h}} : Deletes the previous character (same as backspace).
* {{key press|Ctrl|i}} : Equivalent to the tab key.
* {{key press|Ctrl|j}} : Equivalent to the enter key.
* {{key press|Ctrl|k}} : Clears the line content after the cursor and copies it into the [[clipboard (software)|clipboard]].
* {{key press|Ctrl|l}} : Clears the screen content (equivalent to the command <code>[[clear (Unix)|clear]]</code>).
* {{key press|Ctrl|n}} : ([[wikt:next|next]]) recalls the next command (equivalent to the key {{key press|[[arrow keys|Down]]}}).
* {{key press|Ctrl|o}} : Executes the found command from history, and fetch the next line relative to the current line from the history for editing.
* {{key press|Ctrl|p}} : ([[wikt:previous|previous]]) recalls the prior command (equivalent to the key {{key press|[[arrow keys|Up]]}}).
* {{key press|Ctrl|r}} : ([[wikt:research|research]]) recalls the last command including the specified character(s). A second {{key press|Ctrl|r}} recalls the next anterior command which corresponds to the research
* {{key press|Ctrl|s}} : Go back to the next more recent command of the research (beware to not execute it from a terminal because this command also launches its XOFF). If you changed that XOFF setting, use {{key press|Ctrl|q}} to return.
* {{key press|Ctrl|t}} : Transpose the previous two characters.
* {{key press|Ctrl|u}} : Clears the line content before the cursor and copies it into the [[clipboard (software)|clipboard]].
* {{key press|Ctrl|w}} : Clears the word before the cursor and copies it into the [[clipboard (software)|clipboard]].
* {{key press|Ctrl|y}} : ([[wikt:yank|yank]]) adds the [[clipboard (software)|clipboard]] content from the cursor position.
* {{key press|Ctrl|x}} {{key press|Ctrl|e}} : Edits the current line in the $EDITOR program, or [[vi]] if undefined.
* {{key press|Ctrl|x}} {{key press|Ctrl|r}} : Read in the contents of the inputrc file, and incorporate any bindings or variable assignments found there.
* {{key press|Ctrl|x}} {{key press|Ctrl|u}} : Incremental undo, separately remembered for each line.
* {{key press|Ctrl|x}} {{key press|Ctrl|v}} : Display version information about the current instance of bash.
* {{key press|Ctrl|x}} {{key press|Ctrl|x}} : Alternates the cursor with its old position. (C-x, because x has a crossing shape).
* {{key press|Ctrl|z}} : Sends the signal [[SIGTSTP]] to the current task, which suspends it. To execute it in background one can enter <code>bg</code>. To bring it back from background or suspension <code>fg ['process name or job id']</code> ([[foreground process|foreground]]) can be issued.
* {{key press|Ctrl|_}} : Incremental undo, separately remembered for each line.
* {{key press|Alt|b}} : ([[wikt:backward|backward]]) moves the cursor backward one word.
* {{key press|Alt|c}} : Capitalizes the character under the cursor and moves to the end of the word.
* {{key press|Alt|d}} : Cuts the word after the cursor.
* {{key press|Alt|f}} : ([[wikt:forward|forward]]) moves the cursor forward one word.
* {{key press|Alt|l}} : Lowers the case of every character from the cursor's position to the end of the current word.
* {{key press|Alt|r}} : Cancels the changes and puts back the line as it was in the history.
* {{key press|Alt|u}} : Capitalizes every character from the cursor's position to the end of the current word.
* {{key press|Alt|.}} : Insert the last argument to the previous command (the last word of the previous history entry).
 
== See also <span class="anchor" id="See also"></span> ==
{{Portal|Free software}}
 
{{Portal| Free and open-source software}}
* [[Comparison of command shells]]
*[[Comparison of command shells]]
*{{Section link| Multics#Commands}}, exec_com: the first command processor.<ref name =multics_ec/>
* FTP download from GNU Project of Bash versions 1.14.0 to current.<ref>
{{Citation
| access-date = 8 August 2025
| archive-date = 28 September 2018
| archive-url = https://web.archive.org/web/20180928193215/http://ftp.gnu.org/gnu/bash
| date = 29 August 1996
| publisher = [[GNU Project]]
| title = shell.c
| url = https://ftp.gnu.org/gnu/bash
| url-status = live
| website = [[Free Software Foundation, Inc.]]
}}
</ref>
 
==References= Unix shells ===
{{div col|colwidth=24em}}
{{Reflist}}
* [[Almquist shell | Almquist shell (ash)]]
* [[Bourne shell | Bourne shell (sh)]]
* [[BusyBox]]
* [[C shell | C shell (csh)]]
* [[Almquist shell#dash | Debian-Almquist Shell (dash)]]
* [[Fish (Unix shell) | Fish shell: Friendly Interactive Shell]]
* [[Google Shell | Google Shell (goosh)]] – a UNIX-like front-end for Google Search.
* [[KornShell | Korn shell (ksh)]], of which there are numerous variations.
* nsh – "A command-line shell like fish, but POSIX compatible."<ref>
{{Cite web
| access-date = 8 August 2025
| date = 5 February 2025
| title = Command-line shell
| url = https://wiki.archlinux.org/title/Command-line_shell
| website = archlinux.org
}}</ref>
* osh – "Oil Shell is a Bash-compatible UNIX command-line shell"; available on Arch.
* [[PWB shell | Mashey or Programmer's Workbench shell]]
* [[Qshell | Qshell for IBM i]]
* [[rc (Unix shell) | rc from Plan 9]]
* [[RUNCOM]]
* rush – Restricted User Shell, available on Debian.<ref name =debian.org_shell/>
* [[Stand-alone shell | Stand-alone shell (sash)]]
* scsh – The Scheme Shell.
* [[tcsh | TENEX C shell (tcsh)]]
* [[Thompson shell | Thompson shell (tsh)]]
* [[Toybox]]
* yash – Yet Another Shell, aims "to be the most POSIX-compliant shell in the world"; available on Arch.
* [[Z shell | Z shell (zsh)]]
{{div col end}}
 
<!-- This subsection added from https://ru.wikipedia.org/wiki/Bash on 6 Aug 2025 -->
==External links==
{{wikibooks|Bash Shell Scripting}}
* {{official website|http://www.gnu.org/software/bash/bash.html}}
* [http://www.gnu.org/software/bash/manual/ Bash Reference Manual]&nbsp; ([http://www.gnu.org/software/bash/manual/html_node/index.html HTML] [http://www.gnu.org/software/bash/manual/bash.ps.gz PS] [http://www.gnu.org/software/bash/manual/bash.pdf PDF])
 
=== Graphical interface to scripts ===
* {{tldp|LDP/Bash-Beginners-Guide|Bash Guide for Beginners}}
There are many programs that allow you to create a graphical interface for shell scripts.
* {{tldp|LDP/abs|Advanced Bash Scripting Guide}}
 
* [http://bash.cyberciti.biz/guide/Main_Page Linux Shell Scripting Tutorial (LSST) v2.0 wiki]
* [[curses (programming library)| curses]] - curses is a terminal control library for Unix-like systems, enabling the construction of [[Text-based user interface |text user interfaces]] (TUI) applications.
* [http://www.bashcookbook.com/bashinfo/ "The Comprehensive List of bash Reference Documentation and Examples"]
 
* [http://spsneo.com/blog/2009/09/19/bash-history-tips-and-tricks/ Useful Bash History Tips and Tricks]
* [[Dialog (software) |dialog]] - is a utility that allows you to create dialog boxes in the console, using the [[curses]] and [[ncurses]] libraries.
* [http://www.computerworld.com.au/index.php/id;1591223321;fp;16;fpid;1;pf;1 2008 interview with GNU Bash's maintainer, Chet Ramey]
 
* [http://www.geeksww.com/tutorials/operating_systems/linux/tips_and_tricks/working_bash_environment_variables_beginners_linux.php Working with BASH environment variables]
* gtkdialog - is the most functional utility for creating graphical applications on bash scripts.<ref>
* [http://www.galatech.co.uk/index.php/tutorials/viewpost/100 Video Tutorial for Creating a Bash Script]
{{Cite web
* [http://www.shell-fu.org/lister.php?tag=bash Bash commands and examples]
| access-date = 18 August 2025
* [http://www.markus-gattol.name/ws/bash.html#colorized_shell_prompt Colorized Bash prompt] - how to set up a colorized Bash prompt based on the current connection method (SSH, telnet, etc.).
| author = Hanny Helal
* [http://code.google.com/p/jbash/ jBash Project is a Java Parser for the Bourne Again Shell]
| date = 7 January 2015
* [http://mywiki.wooledge.org/EnglishFrontPage The 'official' channel FAQ for freenode's #bash channel is BashFAQ.]
| publisher = Tecmint
* [http://bashdb.sourceforge.net/ BASHDB - Bash with a built-in debugger.]
| title = Gtkdialog – Create Graphical (GTK+) Interfaces and Dialog Boxes Using Shell Scripts in Linux
* [http://www.digilife.be/quickreferences/QRC/Bash%20Quick%20Reference.pdf Bash Quick Reference card]
| url = https://www.tecmint.com/gtkdialog-create-graphical-interfaces-and-dialog-boxes/
| website = tecmint.com
}}</ref>
 
* kdialog - is a KDE equivalent of zenity.<ref name = linux-mag_sh-click>
{{Cite web
| access-date = 18 August 2025
| at = Issue 99
| author = Kristian Kißling
| date = 2009
| publisher = Linux Magazine
| title = Adding graphic elements to your scripts with Zenity and KDialog
| url = https://www.linux-magazine.com/Issues/2009/99/Zenity-and-KDialog
| website = linux-magazine.com
}}</ref>
 
* [[ncurses]] - a programming library for creating [[Text-based user interface |textual user interfaces]] (TUI's) that work across a wide variety of terminals.
 
* whiptail - is an analogue of the dialog utility, it uses the [[Newt (programming library) |newt]] library.<ref>
{{Cite web
| access-date = 18 August 2025
| publisher = WikiMedia
| title = Bash Shell Scripting/Whiptail
| url = https://en.wikibooks.org/wiki/Bash_Shell_Scripting/Whiptail
| website = wikibooks.org
}}</ref>
 
* xdialog - is a replacement for [[dialog]] that is designed to give programs launched from the terminal an [[X Window System]] interface.
 
* yad - is a fork of zenity, with more features.<ref>
{{Cite web
| access-date = 18 August 2025
| author = Dmitri Popov
| date = 12 March 2012
| publisher = Linux Magazine
| title = Dress Up Bash Scripts with YAD
| url = https://www.linux-magazine.com/Online/Blogs/Productivity-Sauce/Dress-Up-Bash-Scripts-with-YAD
| website = linux-magazine.com
}}</ref>
 
* [[zenity]] - is the most popular application for creating a graphical interface for scripts.<ref name =linux-mag_sh-click/><ref>
{{Cite web
| access-date = 18 August 2025
| at = Issue 247
| author = Pete Metcalfe
| date = 2021
| publisher = Linux Magazine
| title = Create GUI dialogs in one line of code
| url = https://www.linux-magazine.com/Issues/2021/247/Zenity-Dialogs
| website = linux-magazine.com
}}</ref>
 
== Further reading <span class="anchor" id="Further reading"></span> ==
 
*[A]
**{{Cite web
| access-date = 8 August 2025
| publisher = Apple
| quote = Copyright © 2003, 2014 Apple Inc All Rights Reserved. ... Updated: 2014-03-10
| title = Shell Scripting Primer
| url = https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/Introduction/Introduction.html
| website = apple.com
}}
 
*[G]
**{{Cite web
| access-date = 8 August 2025
| publisher = Google
| title = Shell Style Guide
| url = https://google.github.io/styleguide/shellguide.html
| website = github.io
}}
 
*[H]
**{{Cite book
| date = 2003
| first = Neal
| isbn = 978-0380815937
| last = Stephenson
| publisher = HarperCollins
| title = [[In the Beginning... Was the Command Line]]
}}
 
*[I]
**{{Cite web
| access-date = 8 August 2025
| author = M. Jones
| date = 9 December 2011
| publisher = [[IBM]]
| title = Evolution of shells in Linux: From Bourne to Bash and beyond
| url = https://developer.ibm.com/tutorials/l-linux-shells/
| website = ibm.com
}}
 
*[M]
**{{Cite web
| access-date = 8 August 2025
| date = 2 April 1965
| first = Louis
| last = Pouzin
| publisher = [[Massachusetts Institute of Technology]]
| title = The SHELL: A Global Tool for Calling and Chaining Procedures in the System
| url = https://people.csail.mit.edu/saltzer/Multics/Multics-Documents/MDN/MDN-4.pdf
| website = mit.edu
}}
 
*[O]
**{{Cite web
| access-date = 8 August 2025
| first1 = Cameron
| first2 = Bill
| last1 = Newham
| last2 = Rosenblatt
| publisher = O'Reilly Media, Inc.
| quote = Content preview
| title = Learning the Bash Shell, 2e
| url = https://www.oreilly.com/library/view/learning-the-bash/1565923472/ch01s03.html
| website = oreilly.com
}}
 
*[U]
**{{Cite web
| access-date = 19 May 2024
| publisher = [[University of California, Berkeley]]
| title = Scripting Reference :: Scripting with the Bourne-Again Shell (Bash)
| url = https://decal.ocf.berkeley.edu/labs/scripting/
| website = berkeley.edu
}}
**{{Cite web
| access-date = 8 August 2025
| publisher = [[University of California, Berkeley]]
| title = IRIS :: Instructional & Research Information Systems :: FAQ: Unix :: About UNIX Shells
| url = https://iris.eecs.berkeley.edu/faq/unix/
| website = berkeley.edu
}}
 
== Notes ==
{{Notelist}}
 
== References ==
{{Reflist}}
 
{{GNU}}
{{Unix Shellsshells}}
{{Programming languages}}
{{Authority control}}
 
{{DEFAULTSORT:Bash (Unix Shell)}}
[[Category:1989 software]]
[[Category:Cross-platform free software]]
[[Category:Domain-specific programming languages]]
[[Category:Dynamically scoped programming languages]]
[[Category:Free software programmed in C]]
[[Category:GNU Project software]]
[[Category:Scripting languages]]
[[Category:Text-oriented programming languages]]
[[Category:Scripting languages]]
[[Category:Unix shells]]
[[Category:GNU Project software]]
[[Category:Free software programmed in C]]
[[Category:Cross-platform free software]]
[[Category:1989 software]]
 
[[ar:باش]]
[[bg:Bash]]
[[bs:Bash]]
[[ca:Bash]]
[[cs:Bash]]
[[de:Bourne-again shell]]
[[et:Bash]]
[[el:Κέλυφος bash]]
[[es:Bash]]
[[eo:Bash]]
[[eu:Bash]]
[[fa:بش]]
[[fr:Bourne-Again shell]]
[[gl:Bash]]
[[ko:Bash]]
[[hr:Bash]]
[[id:Bourne-Again shell]]
[[is:Bash]]
[[it:Bash]]
[[he:באש]]
[[hu:Bash]]
[[ms:Bash]]
[[nl:Bash]]
[[ja:Bash]]
[[pl:Bash]]
[[pt:Bash]]
[[ro:Bash]]
[[ru:Bash]]
[[sk:Bash]]
[[sr:Баш]]
[[sh:Bash]]
[[fi:Bash]]
[[sv:Bash]]
[[th:แบช]]
[[tr:Bash]]
[[uk:Bash]]
[[zh:Bash]]