Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Bash (Unix shell)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|GNU replacement for the Bourne shell}} {{Use dmy dates|date=March 2014}} {{ Infobox software | author = [[Brian Fox (programmer)|Brian Fox]] | caption = | developer = Chet Ramey | genre = [[Shell (computing)]], [[Unix shell]], [[command language]] | language = Multilingual ([[gettext]]) | latest release date = {{ wikidata | qualifier | preferred | single | Q189248 | P348 | P548 = Q2804309 | P577 }} | latest release version = {{ wikidata | property | preferred | references | edit | Q189248 | P348 | P548 = Q2804309 }} | license = {{ plainlist | * v.4.0+: [[GNU General Public License#Version 3|GPL-3.0-or-later]]<ref name="license">{{Cite web |last=GNU Project |author-link=GNU Project |title=README file |url=https://www.gnu.org/software/bash/ |url-status=live |archive-url=https://web.archive.org/web/20190426210620/http://www.gnu.org/software/bash/ |archive-date=26 April 2019 |access-date=16 April 2014 |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). }}</ref> * v.1.11 - v.3.2: [[GNU General Public License#Version 2|GPL-2.0-or-later]]<ref>{{Cite web |title=bash-1.11 |url=http://www.oldlinux.org/Linux.old/bin/old/bash-1.11/ |url-status=dead |archive-url=https://web.archive.org/web/20211015233550/http://www.oldlinux.org/Linux.old/bin/old/bash-1.11/ |archive-date=15 October 2021 |access-date=9 June 2021 |website=oldlinux.org |quote=See test.c for GPL-2.0-or-later }}</ref> * v.0.99 - v.1.05: [[GNU General Public License#Version 1|GPL-1.0-or-later]]<ref name="bashfaq061">{{Cite web |title=BashFAQ/061 - Greg's Wiki |url=https://mywiki.wooledge.org/BashFAQ/061 |url-status=live |archive-url=https://web.archive.org/web/20210302212811/https://mywiki.wooledge.org/BashFAQ/061 |archive-date=March 2, 2021 |access-date=2021-03-01 |website=mywiki.wooledge.org }}</ref><ref>{{ multiref2 | {{Cite web |title=bash-1.05.tar |url=http://www.oldlinux.org/Linux.old/bin/old/bash-1.05.tar |website=oldlinux.org }} | {{ cite web | 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 = Bash | operating system = {{ Plainlist | * [[Linux]] * [[Unix-like]] * [[macOS]] * [[Windows]] * [[Android (operating system)|Android]] * [[Oracle Solaris]] <!--* [[Haiku (operating system)|Haiku]]--> }} | platform = [[GNU]] | programming language = [[C (programming language)|C]] | released = {{start date and age| 8 June 1989 }} | screenshot = | website = {{URL|www.gnu.org/software/bash/}} }} In [[Computer science|computing]], '''Bash''' (short for "''Bourne Again SHell'',")<ref>{{ multiref2 | {{Cite web |last=[[Richard Stallman]] |date=November 12, 2010 |title=About the GNU Project |url=https://www.gnu.org/gnu/thegnuproject.html |url-status=live |archive-url=https://web.archive.org/web/20110424064815/https://www.gnu.org/gnu/thegnuproject.html |archive-date=24 April 2011 |access-date=13 March 2011 |publisher=Free Software Foundation |quote="Bourne Again Shell" is a play on the name ''Bourne Shell'', which was the usual shell on Unix. }} | {{ cite web | access-date = 13 March 2011 | archive-date = 9 March 2011 | archive-url = https://web.archive.org/web/20110309092607/http://www.markus-gattol.name/ws/bash.html | date = 13 March 2011 | 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 = http://www.markus-gattol.name/ws/bash.html | url-status = dead }} }}</ref> is an [[Human–computer interaction|interactive]] command interpreter and command programming language developed for [[UNIX]]-like operating systems.<ref>{{Cite web |title=Bourne shell |url=https://www.ibm.com/docs/en/aix/latest?topic=shells-bourne-shell |access-date=19 May 2024 |website=ibm.com |quote=The Bourne shell is an interactive command interpreter and command programming language. }}</ref> Created in 1989<ref name="BashBeta">{{Cite newsgroup |url=https://groups.google.com/group/gnu.announce/msg/a509f48ffb298c35?hl=en |title=Bash is in beta release! |last=Brian Fox (forwarded by Leonard H. Tower Jr.) |date=8 June 1989 |newsgroup=gnu.announce |archive-url=https://web.archive.org/web/20130504075535/http://groups.google.com/group/gnu.announce/msg/a509f48ffb298c35?hl=en |archive-date=4 May 2013 |url-status=live |access-date=28 October 2010 }}</ref> by Brian Fox for the [[GNU Project]], it is supported by the [[Free Software Foundation]] and designed as a 100% [[free software|free]] alternative for the [[Bourne shell]] (<code>sh</code>) and other proprietary Unix shells.<ref>{{ multiref2 | {{Cite web |title=GNU in a Nutshell |url=https://www.gnu.org/gnu/about-gnu.html |access-date=19 May 2024 |website=gnu.org |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. }} | {{ cite web | access-date = 19 May 2024 | 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 = 19 May 2024 | quote = GNU is an operating system which is 100% free software. | title = GNU Software | url = https://www.gnu.org/software/software.en.html | website = gnu.org }} | {{ cite web | access-date = 19 May 2024 | 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's Who | url = https://www.gnu.org/bulletins/bull7.html#SEC3 | website = gnu.org }} }}</ref> Since its inception, Bash has gained widespread adoption and is commonly used as the default [[login]] shell for numerous [[Linux]] distributions.<ref>{{ multiref2 | {{cite journal | access-date = 21 March 2011 | archive-date = 6 July 2011 | archive-url = https://web.archive.org/web/20110706103704/http://www.computerworld.com.au/article/222764/a-z_programming_languages_bash_bourne-again_shell/?pp=2&fp=16&fpid=1 | date = 30 May 2008 | first = Naomi | journal = Computerworld | last = Hamilton | page = 2 | 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 = http://www.computerworld.com.au/article/222764/a-z_programming_languages_bash_bourne-again_shell/?pp=2&fp=16&fpid=1 | url-status = dead }} | {{cite web | title=The A-Z of Programming Languages: BASH/Bourne-Again Shell | website=A-Z 0.01 documentation | date=2008-05-30 | url=https://a-z.readthedocs.io/en/latest/bash.html }} | {{cite web| publisher= University of South Carolina |title=The A-Z of Programming Languages | url = https://cse.sc.edu/~mgv/csce330f16/pres/az.pdf }} }}</ref><ref name="cmpwrld_intrw2008">{{Cite web|last=Hamilton |first=Naomi |date=30 March 2008 |title=The A-Z of Programming Languages: BASH/Bourne-Again Shell | url=http://www.computerworld.com.au/article/222764/ | archive-url=https://web.archive.org/web/20160811002459/http://www.computerworld.com.au/article/222764/ | archive-date=2016-08-11 | url-status=dead |website=[[Computerworld]]}}</ref><ref name="goftw2015">{{Cite web |date=14 December 2015 |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 |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/ |archive-date=31 Jul 2020 |access-date=April 26, 2025}}</ref> It 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|last=Torvalds |first=Linus Benedict |date=August 1991 |title=What would you like to see most in minix? |newsgroup=comp.os.minix |url=https://groups.google.com/group/comp.os.minix/msg/b813d52cbc5a044b |access-date=2009-09-06 |quote=I've currently ported bash(1.08) and gcc(1.40), and things seem to work. }}</ref> It is available on nearly all modern operating systems, making it a versatile tool in various computing environments. As a [[command-line interface]] (CLI), Bash operates within a terminal emulator, or [[terminal emulator|text window]], where users input commands to execute various tasks. It also supports the execution of commands from files, known as [[shell script]]s, facilitating [[automation]]. In keeping with Unix shell conventions, Bash incorporates a rich set of features. The [[keyword (computer programming)|keywords]], [[syntax (programming languages)|syntax]], [[scope (computer science)#Dynamic scoping|dynamically scoped]] variables, and other basic features of the [[formal language|language]] are all copied from the Bourne shell, (<code>sh</code>). Other features, e.g., history, are copied from the [[C shell]], (<code>csh</code>), and the [[Korn Shell]], (<code>ksh</code>). It is a [[POSIX]]-compliant shell with extensions. == History == While Bash was developed for UNIX and UNIX-like operating systems, such as GNU/Linux, it is also available on Android, macOS, Windows, and numerous other current and historical operating systems.<ref>{{Cite web |title=Bash FAQ, version 4.14 |url=ftp://ftp.cwru.edu/pub/bash/FAQ |url-status=dead |archive-url=https://web.archive.org/web/20180901171316/ftp://ftp.cwru.edu/pub/bash/FAQ |archive-date=September 1, 2018 |access-date=April 9, 2016 |df=mdy-all }}</ref> "Although there have been attempts to create specialized shells, the Bourne shell derivatives continue to be the primary shells in use."<ref name="developer.ibm.com">{{Cite web |date=9 December 2011 |title=Evolution of shells in Linux |url=https://developer.ibm.com/tutorials/l-linux-shells/}}</ref> === Timeline === {{Split portions|subsections=y |date=January 2025 |Unix Shell|Bourne shell|Thompson shell|Korn shell|C shell}} {{timeline-start}} {{timeline-item|{{start date|1963}}|2= While at MIT developing for the [[Compatible Time-Sharing System]] operating system, [[Louis Pouzin]] wrote ''''[[RUNCOM]]'''', "a sort of shell driving the execution of command scripts, with argument substitution." He "felt that commands should be usable as building blocks for writing more commands, just like subroutine libraries."<ref name="Pouzin, 2000">{{Cite web |last=Louis Pouzin |date=25 November 2000 |title=The Origin of the Shell |url=https://multicians.org/shell.html}}</ref> * "There was a facility that would execute a bunch of commands stored in a file; it was called <code>runcom</code> for "run commands", and the file began to be called "a runcom". <code>rc</code> in Unix is a fossil from that usage."<ref name = "Indiana University, 2009"> {{ cite web | date = 5 February 2009 | publisher = Indiana University | url = http://kb.iu.edu/data/abnd.html | archive-url = https://web.archive.org/web/20100610011504/http://kb.iu.edu/data/abnd.html | archive-date = 10 June 2010 | title = In Unix, what do some obscurely named commands stand for? | url-status = dead }}</ref><ref>{{Cite web |title=Vicki Brown, Bio |url=https://www.oreilly.com/pub/au/2933 |publisher=O'Reilly Media}}</ref> }} {{timeline-item|{{start date|1964}}|2= Development began on MULTICS at MIT. }} {{timeline-item|{{start date|1965}}|2= <!-- Suggestion 2 / 8 -- 06 Jan 2025 --> {{Timeline-event|date={{start date text|April 2, 1965}}|event=MIT publishes ''"The SHELL, A Global Tool for Calling and Chaining Procedures in the System,"'' by Louis Pouzin. The paper describes many features found in Bash.<ref name="Pouzin, 1965">{{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}}</ref> }} {{blockquote |text = "[[Christopher Strachey]], a British scientist, had visited MIT about that time, and his '''macro-generator''' design appeared to me a very solid base for a command language, in particular the techniques for quoting and passing arguments. Without being invited on the subject, I wrote a paper explaining how the Multics command language could be designed with this objective. And I coined the word "shell" to name it."<ref name="Pouzin, 2000" />}} * "It (i.e., the [[Thompson Shell]]) was modeled after the Multics shell, developed in 1965 by American software engineer [[Glenda Schroeder]]. '''Schroeder's Multics shell''' was itself modeled after the RUNCOM program Louis Pouzin showed to the Multics Team. }} {{ timeline-item|{{start date|1968}}|2= ALGOL68 was released. The Bourne shell drew from it the concepts of program flow, closed forms (<code>if...fi</code>, <code>case...esac</code>), and completion of substitutions anywhere.<ref name="Bourne, 2015">{{ multiref2 | {{Cite web |title=BSDCan 2015, The Technical BSD Conference |date=17 April 2016 |url=https://www.bsdcan.org/2015/schedule/events/612.en.html |access-date=20 January 2025}} | {{ cite web | access-date = 20 January 2025 | author = Stephen R. Bourne | date = 12 June 2015 | title = Early days of Unix and design of sh | url = https://www.bsdcan.org/2015/schedule/attachments/306_srbBSDCan2015.pdf }} }}</ref> These closed forms and the <code>for...done</code> and <code>while...done</code> loop were defined as "Guarded Commands" in 1976 by Dijkstra.<ref name="Dijkstra, 1976">{{Cite web |last=Edsger W. Dijkstra |date=27 January 1975 |title=Guarded commands, non-determinacy and formal derivation of programs |url=https://www.cs.utexas.edu/~EWD/ewd04xx/EWD472.PDF |access-date=20 January 2025 |quote='Guarded command,' a statement list prefixed by a Boolean expression: only when this boolean expression is initially true, is the statement list eligible for execution.}}</ref> }} {{timeline-item|{{start date|1969}}|2= The [[Multics|MULTICS]] operating system was introduced as a collaboration between MIT, GE and Bell Labs. "It is also the first to have a command processor implemented as ordinary user code – an idea later used in the Unix shell."[[Multics|Multics Wikipage]] It was called exec_com or ec.<ref name="Multicians, Unix">{{Cite web |title=Unix and Multics |url=https://www.multicians.org/unix.html |website=www.multicians.org}}</ref><ref name="Multics History, info segment on exec_com">{{Cite web |title=Multics History, info segment on exec_com |url=https://web.mit.edu/multics-history/source/Multics/doc/info_segments/exec_com.info}}</ref> }} {{timeline-item|{{start date|1971}}|2= "Ken Thompson (of Bell Labs) developed the first shell for UNIX called the 'V6 shell'." Its sole purpose was to serve as an interactive shell. It supported external commands called <code>glob</code>, for pattern matching, and <code>if</code>, for conditional expressions. "The shell introduced a compact syntax for redirection (<code><</code> <code>></code> and <code>>></code>) and piping (<code>{{!}}</code> or <code>^</code>) that has survived into modern shells. You can also find support for invoking sequential commands (with <code>;</code>) and asynchronous commands (with <code>&</code>)."<ref name="developer.ibm.com" /> It also incorporated a goto command. "However, the Thompson shell was still distributed with the system as <code>osh</code>."<ref>https://v6sh.org/ V6 Sh History</ref> }} {{timeline-item|{{start date|1972}}|2= Pipelines were introduced in Unix.<ref name="Bourne, 2015" /> }} {{timeline-item|{{start date|1973}}|2= UNIX, originally written by Ken Thompson, Dennis Ritchie, and Brian Kernighan among others, was released by AT&T (wikipedia UNIX page). }} {{timeline-item|{{start date|1975}}|2=<nowiki/> * "PWB Mashey shell started mid 1975."<ref name="Bourne, 2015" /> * {{Timeline-event|date={{start date text|September 1975}}|event=[[Digital Equipment Corporation]] released the VT52, which "provided a screen of 24 rows and 80 columns of text and supported all 95 ASCII characters, as well as... bi-directional scrolling" and, unlike its predecessor the VT50, lower case support ([[VT52]]).}} }} {{timeline-item|{{start date|1977}}|2=<nowiki/> * The American National Standard Code for Information Interchange, or "ASCII," is published by the National Institute of Science and Technology, or "NIST,"as FIPS PUB 1-2.<ref name="NIST, ASCII Publication, PDF c1977">{{Cite web |title=NIST, ASCII Publication, PDF c1977 |url=https://nvlpubs.nist.gov/nistpubs/Legacy/FIPS/fipspub1-2-1977.pdf}}</ref> The ASCII character set is still with us today as a core component of writing portable shell scripts. * "The Bourne shell was introduced.... Created by Stephen Bourne at AT&T Bell Labs for V7 UNIX, [it] remains a useful shell today (in some cases, as the default root shell)." "Bourne introduced control flows, loops, and variables into scripts, providing a more functional language to interact with the operating system (both interactively and noninteractively). The shell also permitted you to use shell scripts as filters, providing integrated support for handling signals, but lacked the ability to define functions. Finally, it incorporated a number of features we use today, including command substitution (using back quotes) and HERE documents to embed preserved string literals within a script."<ref name="developer.ibm.com" /> It used the -eq, -ne, -lt style of test operators * The [[KornShell|Korn Shell]] was introduced at around the same time as was the Bourne shell. * [[OpenVMS]] - Initial Release.<ref>{{Cite web |title=Installing the new GNU packages |url=https://sourceforge.net/p/gnv/wiki/InstallingGNVPackages/ |url-status=live |archive-url=https://web.archive.org/web/20201003182204/https://sourceforge.net/p/gnv/wiki/InstallingGNVPackages/ |archive-date=October 3, 2020 |access-date=2020-09-04}}</ref> It included Bash at some later point. }} {{timeline-item|{{start date|1978}}|2=<nowiki/> * [[C shell]] - Initial release. Created by Bill Joy while he was at Berkeley, and released with 2BSD. "A useful feature introduced by Bill Joy in the C shell was command history. This feature maintained a history of the previously executed commands and allowed the user to review and easily select previous commands to execute. For example, typing the command history would show the previously executed commands. The up and down arrow keys could be used to select a command, or the previous command could be executed using !!. It's also possible to refer to arguments of the prior command; for example, !* refers to all arguments of the prior command, where !$ refers to the last argument of the prior command."<ref name="developer.ibm.com" /> "csh, tcsh, zsh, ash, and scsh are all released under the BSD or a BSD-like license." * {{Timeline-event|date={{start date text|August 1978}}|event=[[Digital Equipment Corporation]] introduced the [[VT100]].}} }} {{timeline-item|{{start date|1983}}|2=<nowiki/> * The TENEX C shell "introduced file name and command completion in addition to command-line editing features. The [[tcsh]] was developed by Ken Greer at Carnegie Mellon University."<ref name="developer.ibm.com" /> The shebang, or hashbang symbol was available in tcsh. Also, positional parameters as the argv array including argv[1], the $0 shell variable as argv[0], the Count of Indices parameter expansion $#var, the -d and -x operators of a testing syntax regarding directory and executability tests, respectively, the ! negate symbol, a looping construct in the foreach command, the set, echo and exit commands, variable assignment and arithmetic contexts "@ count = $count + 1", and familiar double quoting rules. * [[Novell NetWare]] - Initial release. It included Bash at some later point. }} {{timeline-item|{{start date|1984}}|2= "The IEEE POSIX work started in 1984 as an outgrowth of work initiated in the /usr/group organization to build a standard on the two variations of UNIX at the time - version 6 and BSD (Berkeley)."<ref name="POSIX Impact">{{Cite web |title=JimIsaak - POSIX Impact |url=https://sites.google.com/site/jimisaak/posix-impact |website=sites.google.com}}</ref> }} {{timeline-item|{{start date|1986}}|2= The documents which would become known as "POSIX" started out as a trial use standard by the IEEE. By some it is considered a de facto standard.<ref name="Usenix ';login:' Feb 2007">{{Cite web |title=An Update On Standards |url=https://www.usenix.org/legacy/bodinfo/login0207.html |website=www.usenix.org}}</ref> }} {{timeline-item|{{start date|1988}}|2=<nowiki/> * {{Timeline-event|date={{start date text|January 10, 1988}}|event= [[Brian Fox (computer programmer)|Brian Fox]] began [[Computer programming|coding]] Bash<ref>{{Citation |last=Brian Fox |title=shell.c |date=August 29, 1996 |url=http://ftp.gnu.org/gnu/bash/bash-1.14.7.tar.gz |access-date=November 1, 2010 |archive-url=https://web.archive.org/web/20180928193215/http://ftp.gnu.org/gnu/bash/bash-1.14.7.tar.gz |archive-date=September 28, 2018 |url-status=live |publisher=[[Free Software Foundation]] |quote=Birthdate: Sunday, January 10th, 1988. Initial author: Brian Fox}}</ref> after [[Richard Stallman]] became dissatisfied with the lack of progress being made by a prior developer.<ref name="GNUBSD">{{Cite newsgroup |url=https://groups.google.com/g/comp.unix.questions/c/iNjWwkyroR8/m/yedr9yDWSuQJ |title=GNU + BSD = ? |last=[[Richard Stallman]] (forwarded with comments by Chet Ramey) |date=February 10, 1988 |newsgroup=comp.unix.questions |message-id=2362@mandrill.CWRU.Edu |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. |archive-url=https://web.archive.org/web/20211228023030/https://groups.google.com/g/comp.unix.questions/c/iNjWwkyroR8/m/yedr9yDWSuQJ |archive-date=December 28, 2021 |url-status=live |access-date=December 28, 2021}}</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 = GNUBSD/><ref>{{Cite web |last=[[Richard Stallman]] |date=3 October 2010 |title=About the GNU Project |url=https://www.gnu.org/gnu/thegnuproject.html |url-status=live |archive-url=https://web.archive.org/web/20110424064815/https://www.gnu.org/gnu/thegnuproject.html |archive-date=April 24, 2011 |access-date=21 March 2011 |publisher=[[Free Software Foundation]] |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>}} * "The first version of the IEEE Std 1003 was published in 1988 with the reference 'IEEE IX'," but these standards would not specify requirements for a "command interpreter," or "Shell and Utilities," until later. "At the suggestion of Richard Stallman, this was changed to POSIX for 'portable operating system interface'."<ref name="POSIX Impact" /><ref name="stallman.org posix">{{Cite web |title=The origin of the name POSIX. |url=https://stallman.org/articles/posix.html |website=stallman.org}}</ref> The POSIX "interface enables application writers to write portable applications {{--}} it was developed with that goal in mind."<ref name="POSIX Backgrounder">{{Cite web |title=POSIX.1 Backgrounder |url=https://www.opengroup.org/austin/papers/backgrounder.html |website=www.opengroup.org}}</ref> }} {{timeline-item|{{start date|1989}}|2=<nowiki/> * {{Timeline-event|date={{start date text|May 30, 1989}}|event=Kenneth Almquist's ash shell - Initial release.<ref name="Mascheck, Ash Variants">{{Cite web |title=ash variants |url=https://www.in-ulm.de/~mascheck/various/ash/ |website=www.in-ulm.de}}</ref>}} * {{Timeline-event|date={{start date text|June 8, 1989}}|event=Fox released Bash as a beta, version 0.99.<ref name = BashBeta/> 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 name="Evolution of shells in Linux ">{{Cite web |date=9 December 2011 |title=Evolution of shells in Linux |url=https://developer.ibm.com/tutorials/l-linux-shells/}}</ref> Eventually it supported "regular expressions (similar to Perl), and associative arrays."}} * Microsoft/IBM [[DOS]] via the [[DJGPP]] project - Initial release. }} {{timeline-item|{{start date|1992}}|2=<nowiki/> * POSIX.2: Shell and Utilities (IEEE Std 1003.2-1992) was published. * Brian Fox remained the primary maintainer until sometime between mid-1992<ref>{{Cite newsgroup |url=https://groups.google.com/group/gnu.misc.discuss/msg/4f42c739cd7e8bd8 |title=January 1993 GNU's Bulletin |last=len (g...@prep.ai.mit.edu) |date=April 20, 1993 |newsgroup=gnu.announce |message-id=gnusenet930421bulletin@prep.ai.mit.edu |archive-url=https://web.archive.org/web/20210302213455/https://groups.google.com/forum/ |archive-date=March 2, 2021 |url-status=live |access-date=October 28, 2010}}</ref> and mid-1994.<ref name="Bourne shell grammar">{{Cite web |last=Ramey |first=Chet |date=August 1, 1994 |title=Bash - the GNU shell (Reflections and Lessons Learned) |url=http://www.linuxjournal.com/article/2800#N0xa50890.0xb46380 |url-status=live |archive-url=https://web.archive.org/web/20081205082152/http://www.linuxjournal.com/article/2800 |archive-date=December 5, 2008 |access-date=November 13, 2008 |website=[[Linux Journal]]}}</ref><ref>{{Citation |last=Chet Ramey |title=Dates in your Computerworld interview |date=October 31, 2010 |url=https://www.scribd.com/doc/40556434/2010-10-31-Chet-Ramey-Early-Bash-Dates |access-date=October 31, 2010 |archive-url=https://web.archive.org/web/20120720124341/http://www.scribd.com/doc/40556434/2010-10-31-Chet-Ramey-Early-Bash-Dates |archive-date=July 20, 2012 |url-status=live}}</ref> His responsibility was then transitioned to another early contributor, Chet Ramey.<ref>{{multiref2| {{Cite web |last=Ramey |first=Chet |date=2021-04-20 |title=The GNU Bourne-Again Shell |url=https://tiswww.case.edu/php/chet/bash/bashtop.html |access-date=1 March 2022 |website=Technology Infrastructure Services |publisher=[[Case Western Reserve University]]}} | {{Cite newsgroup |url=https://groups.google.com/group/gnu.bash.bug/msg/1fc7b688f5d44438?hl=en |title=Bash 0.99 fixes & improvements |last=Chet Ramey |date=June 12, 1989 |newsgroup=gnu.bash.bug |archive-url=https://web.archive.org/web/20121110194014/http://groups.google.com/group/gnu.bash.bug/msg/1fc7b688f5d44438?hl=en |archive-date=November 10, 2012 |url-status=live |access-date=November 1, 2010 }} | {{Cite newsgroup |url=https://groups.google.com/group/gnu.bash.bug/msg/072a03645663caea?hl=en |title=Some bash-1.02 fixes |last=Chet Ramey |date=July 24, 1989 |newsgroup=gnu.bash.bug |archive-url=https://web.archive.org/web/20121110194034/http://groups.google.com/group/gnu.bash.bug/msg/072a03645663caea?hl=en |archive-date=November 10, 2012 |url-status=live |access-date=October 30, 2010 }} | {{Cite newsgroup |url=https://groups.google.com/group/gnu.bash.bug/msg/e6112ccc8866e2f4?hl=en |title=Availability of bash 1.05 |last=Brian Fox |date=March 2, 1990 |newsgroup=gnu.bash.bug |archive-url=https://web.archive.org/web/20121110194052/http://groups.google.com/group/gnu.bash.bug/msg/e6112ccc8866e2f4?hl=en |archive-date=November 10, 2012 |url-status=live |access-date=October 30, 2010 }} }}</ref><ref name="cmpwrld_intrw2008" /><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 |last1=Bresnahan |first1=Christine |url=https://books.google.com/books?id=2P3zBgAAQBAJ&q=%22most+popular%22+linux+shell&pg=PA5 |title=CompTIA Linux+ Powered by Linux Professional Institute Study Guide: Exam LX0-103 and Exam LX0-104 |last2=Blum |first2=Richard |date=April 2015 |publisher=John Wiley & Sons, Inc. |isbn=978-1-119-02122-3 |edition=3rd |page=5 |quote=In Linux, most users run bash because it is the most popular shell. |access-date=June 6, 2016 |archive-url=https://web.archive.org/web/20210302212409/https://books.google.com/books?id=2P3zBgAAQBAJ&q=%22most+popular%22+linux+shell&pg=PA5 |archive-date=March 2, 2021 |url-status=live}}</ref><ref>{{Cite book |last1=Danesh |first1=Arman |url=https://books.google.com/books?id=tIjrVYbZmUAC&q=bash+most+popular+unix+shell&pg=PA363 |title=Mastering Linux |last2=Jang |first2=Michael |date=February 2006 |publisher=John Wiley & Sons, Inc. |isbn=978-0-7821-5277-7 |page=363 |quote=The Bourne Again Shell (bash) is the most common shell installed with Linux distributions. |access-date=June 6, 2016 |archive-url=https://web.archive.org/web/20210302212410/https://books.google.com/books?id=tIjrVYbZmUAC&q=bash+most+popular+unix+shell&pg=PA363 |archive-date=March 2, 2021 |url-status=live}}</ref> }} {{timeline-item|{{start date|1992}}|2= "The first eight entries in (POSIX) Portable Character Set are defined in the ISO/IEC 6429:1992 standard." They are null, alert, backspace, tab, carriage-return, newline, vertical-tab and form-feed.<ref name="Portable Character Set">{{Cite web |title=Character Set |url=https://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap06.html |website=pubs.opengroup.org}}</ref> }} {{timeline-item|{{start date|1994}}|2=<nowiki/> * {{Timeline-event|date={{start date text|January 26, 1994}}|event=Debian - initial release. Bash is the default interactive and non-interactive shell.<ref name="Debian Wiki: Shell" />}} }} {{timeline-item|{{start date|1995}}|2=<nowiki/> * [[Cygwin]] - Initial release. * [[BeOS]] - Initial release.<ref name="Forbes, A Desktop Alternative">{{Cite web |title=A desktop alternative |url=https://www.forbes.com/1999/01/25/feat.html |website=Forbes}}</ref><ref>{{Cite web |title=Appendix A: Using the BeOS Command Line Shell |url=http://testou.free.fr/www.beatjapan.org/mirror/www.be.com/documentation/user_docs/app_a_commandline.html |website=testou.free.fr}}</ref> }} {{timeline-item|{{start date|1996}}|2=<nowiki/> * {{Timeline-event|date={{start date text|December 31, 1996}}|event= Chet Ramey released bash 2.0. The license was GPL-2.0-or-later.}} }} {{timeline-item|{{start date|1997}}|2=<nowiki/> * {{Timeline-event|date={{start date text|June 5, 1997}}|event=Bash 2.01 is released.}} * Almquist shell, ash, ported from NetBSD to Debian by Herbert Xu. }} {{timeline-item|{{start date|1998}}|2=<nowiki/> * {{Timeline-event|date={{start date text|April 18, 1998}}|event=Bash 2.02 is released.}} * [[MinGW]] (32-bit) - Initial release. * A group of Standards Committees from the IEEE, the Open Group and the ISO/IEC began working on the Single UNIX Specification v 3; they together became known as the Austin Group. A Technical Standard for Shell and Utilities was created in The Open Group Base Specifications, Issue 6, which is itself a part of the Single UNIX Specification v 3.<ref name="Single UNIX Specification v 3 - Overview">{{Cite web |title=The Single UNIX Specification, Version 3 - Overview |url=https://unix.org/version3/overview.html |website=unix.org}}</ref> A focus of their work was to "collect into a single document" practices which had been proven to work in industry and academia while making "minimal changes to existing application code."<ref name="POSIX Backgrounder" /> }} {{timeline-item|{{start date|1999}}|2=<nowiki/> * {{Timeline-event|date={{start date text|February 19, 1999}}|event= Bash 2.03 is released.}} }} {{timeline-item|{{start date|2000}}|2=<nowiki/> * {{Timeline-event|date={{start date text|March 21, 2000}}|event=Bash 2.04 is released. }} * The Korn shell is released as open source under the Common Public License. * "The rest of the characters" in the POSIX Portable Character Set "are defined in the ISO/IEC 10646-1:2000 standard." They comprise the remainder of the characters on a U.S. qwerty keyboard from <nowiki><space> to <tilde></nowiki>.<ref name="Portable Character Set" /> * BeOS - Final release * Darwin OS - Initial release. Bash is one of the available shells.<ref name="Evolution of shells in Linux" /> * {{Timeline-event|date={{start date text|September 14, 2000}}|event=Bug-bash mailing list exists.<ref>{{Cite mailing list |last=Chet Ramey |title=Re: Line-Edit mode is lost if "set -o vi" is in any files sourced on login. |mailing-list=bug-bash |date=14 Sep 2000 |url=https://lists.gnu.org/archive/html/bug-bash/2000-09/msg00000.html}}</ref>}} }} {{timeline-item|{{start date|2001}}|2=<nowiki/> * {{Timeline-event|date={{start date text|April 9, 2001}}|event=Bash 2.05 released.<ref>{{Cite mailing list |last=Chet Ramey |title=Bash-2.05 available for FTP |mailing-list=bug-bash |date=9 Apr 2001 |url=https://lists.gnu.org/archive/html/bug-bash/2001-04/msg00047.html}}</ref>}} * A POSIX-2001 Standard is published which includes a "Commands and Utilities" section. The Austin Group and the Single Unix Specification is involved.<ref name="Single UNIX Specification v 3 - Overview" /> }} {{timeline-item|{{start date|2002}}|2=<nowiki/> * {{Timeline-event|date={{start date text|September 2002}}|event= In Debian, version 0.4.1 of ash was renamed to dash.}} }} {{timeline-item|{{start date|2003}}|2=<nowiki/> * 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 |last1=Foster-Johnson |first1=Eric |url=https://books.google.com/books?id=dwIRERUpQPEC&q=bash+most+popular+unix+shell&pg=PA6 |title=Beginning Shell Scripting |last2=Welch |first2=John C. |last3=Anderson |first3=Micah |date=April 2005 |publisher=John Wiley & Sons, Inc. |isbn=978-0-7645-9791-6 |page=6 |quote=Bash is by far the most popular shell and forms the default shell on Linux and Mac OSX systems. |access-date=June 6, 2016 |archive-url=https://web.archive.org/web/20210302212410/https://books.google.com/books?id=dwIRERUpQPEC&q=bash+most+popular+unix+shell&pg=PA6 |archive-date=March 2, 2021 |url-status=live}}</ref> It was available on OS X 10.2 Jaguar as well where the default shell was tcsh. * A POSIX-2003 Shell and Utilities standard is published by the IEEE. "This is a component product standard for the mandatory shell and utilities related functionality;" a POSIX Certification Program exists.<ref name="POSIX FAQ v 1.18">{{Cite web |title=POSIX.1 FAQ |url=https://www.opengroup.org/austin/papers/posix_faq.html |website=www.opengroup.org}}</ref> }} {{timeline-item|{{start date|2004}}|2=<nowiki/> * {{Timeline-event|date={{start date text|July 27, 2004}}|event=Bash 3.0 is released.<ref>{{Cite mailing list |title=Bash-3.0 available for FTP |mailing-list=bug-bash |url=https://lists.gnu.org/archive/html/bug-bash/2004-07/msg00255.html}}</ref>}} * POSIX-2004 is published.<ref name="POSIX-2004">{{Cite web |title=The Open Group Base Specifications Issue 6 |url=https://pubs.opengroup.org/onlinepubs/009695399/ |website=pubs.opengroup.org}}</ref> }} {{timeline-item|{{start date|2005}}|2=<nowiki/> * {{Timeline-event|date={{start date text|December 9, 2005}}|event=Bash 3.1 is released.<ref>{{Cite mailing list |title=Bash-3.1 released |mailing-list=bug-bash |url=https://lists.gnu.org/archive/html/bug-bash/2005-12/msg00018.html}}</ref>}} * [[Mingw-w64]] {{--}} Initial release. }} {{timeline-item|{{start date|2006}}|2=<nowiki/> * {{Timeline-event|date={{start date text|October 12, 2006}}|event=Bash 3.2 released.<ref>{{Cite mailing list |title=Bash-3.2 available for FTP |mailing-list=bug-bash |url=https://lists.gnu.org/archive/html/bug-bash/2006-10/msg00057.html}}</ref> The license was GPL-2.0-or-later.}} * Ubuntu adopts dash as its default shell. }} {{ timeline-item | {{ start date | 2008 }} | 2= POSIX-2008 is released by the IEEE. "This standard defines a standard source level interface to the shell and utility functionality required by application programs, including shell scripts."<ref name="POSIX FAQ v 1.18" /> }} {{ timeline-item | {{ start date text | 2009 }} | 2 = <nowiki/> * {{ Timeline-event | date = {{ start date text | February 20, 2009 }} | event = Bash 4.0 is released<ref>{{Cite mailing list|title=Bash-4.0 available for FTP |url=https://lists.gnu.org/archive/html/bug-bash/2009-02/msg00164.html |mailing-list=bug-bash}}</ref> Its license is GPL-3.0-or-later. }} * Novell Netware - final release * {{ Timeline-event | date = {{ start date text | September 14, 2009 }} | event = [[Haiku (operating system)]] - Initial release.<ref>{{Cite web |date=September 14, 2009 |title=Haiku Project Announces Availability of Haiku R1/Alpha 1 |url=https://www.haiku-os.org/news/2009-09-13_haiku_project_announces_availability_haiku_r1alpha_1 |website=Haiku Project}}</ref> "Haiku's interface to the shell, by default," is bash.<ref>{{Cite web |title=Terminal |url=https://www.haiku-os.org/docs/userguide/en/applications/terminal.html |website=www.haiku-os.org}}</ref> As of September 13, 2024, Haiku remains in beta.<ref>{{Cite web |title=Get Haiku! |url=https://www.haiku-os.org/get-haiku/r1beta5/ |website=Haiku Project}}</ref> }} }} {{ timeline-item | {{ start date text | 2010 }} | 2 = <nowiki/> * {{ Timeline-event | date = {{ start date text | January 2, 2010 }} | event = Bash 4.1 is released.<ref>{{Cite mailing list|title=Bash-4.1 available for FTP |url=https://lists.gnu.org/archive/html/bug-bash/2010-01/msg00000.html |mailing-list=bug-bash}}</ref> }} }} {{ timeline-item | {{ start date text | 2011 }} | 2 = <nowiki/> * {{ Timeline-event | date = {{ start date text | February 6, 2011 }} | event = Debian Lenny is released with Bash as its default interactive shell, and dash as its default non-interactive shell.<ref>{{Cite web |title="Debian Wiki: Shell" |url=https://wiki.debian.org/Shell |quote="Dash lacks many of the features one would expect in an interactive shell, which allows it to be faster and more memory efficient than Bash."}}</ref> }} * {{ Timeline-event | date = {{ start date text | February 14, 2011 }} | event = Bash 4.2 is released.<ref>{{Cite mailing list|title=Bash-4.2 available for FTP |url=https://lists.gnu.org/archive/html/bug-bash/2011-02/msg00134.html |mailing-list=bug-bash}}</ref> }} }} {{ timeline-item | {{ start date | 2012 }} | 2 = On [[Solaris (operating system)|Solaris]] 11, "the default user shell is the Bourne-again (bash) shell."<ref>{{Cite web |title=User Environment Feature Changes |url=https://docs.oracle.com/cd/E23824_01/html/E24456/userenv-1.html |url-status=live |archive-url=https://web.archive.org/web/20180612144748/https://docs.oracle.com/cd/E23824_01/html/E24456/userenv-1.html |archive-date=June 12, 2018 |access-date=June 8, 2018 |publisher=Oracle}}</ref> }} {{ timeline-item | {{ start date | 2013 }} | 2 = POSIX-2013 is released by the IEEE.<ref>{{Cite web |title=The Open Group Base Specifications Issue 7, 2013 Edition |url=https://pubs.opengroup.org/onlinepubs/9699919799.2013edition/ |website=pubs.opengroup.org}}</ref> }} {{timeline-item|{{start date|2014}}|2=<nowiki/> * {{Timeline-event|date={{start date text|February 27, 2014}}|event= Bash 4.3 is released.<ref>{{Cite mailing list |title=Bash-4.3 available for FTP |mailing-list=bug-bash |url=https://lists.gnu.org/archive/html/bug-bash/2014-02/msg00081.html}}</ref>}} * {{Timeline-event|date={{start date text|8 September 2014}}|event=[[Shellshock (software bug)]].<ref name="Mitre, CVE-2014-6271">{{Cite web |title=CVE - CVE-2014-6271 |url=https://cve.mitre.org/cgi-bin/cvename.cgi?name=cve-2014-6271 |website=cve.mitre.org}}</ref> Patches to fix the bugs were made available soon after the bugs were identified.<ref name="Bug-bash, Bash 3.0 Official Patch 1">{{Cite mailing list |title=Bash 3.0 Official Patch 1 |mailing-list=bug-bash |url=https://lists.gnu.org/archive/html/bug-bash/2004-09/msg00083.html}}</ref>}} }} {{timeline-item|{{start date|2015}}|2= [[Termux]] and other terminal emulation applications provide availability of Bash on [[Android (operating system)|Android]]. }} {{timeline-item|{{start date|2016}}|2=<nowiki/> * {{Timeline-event|date={{start date text|April 26, 2016}}|event= [[Windows 10]] Insider Preview Build 14332 supports installation of Bash on Ubuntu in the newly released [[Windows Subsystem for Linux]].<ref name="Windows 10 Insider Preview Build 14332">{{Cite web |last=Aul |first=Gabe |date=26 April 2016 |title=Announcing Windows 10 Insider Preview Build 14332 |url=https://blogs.windows.com/windows-insider/2016/04/26/announcing-windows-10-insider-preview-build-14332/ |website=Windows Insider Blog}}</ref><ref>{{multiref2| {{Cite web |date=September 28, 2016 |title=How to install Bash shell command-line tool on Windows 10 |url=http://www.windowscentral.com/how-install-bash-shell-command-line-windows-10 |url-status=live |archive-url=https://web.archive.org/web/20161120213017/http://www.windowscentral.com/how-install-bash-shell-command-line-windows-10 |archive-date=November 20, 2016 |access-date=November 20, 2016}} | {{ cite web | access-date=July 8, 2016 | archive-date=September 24, 2019 | archive-url=https://web.archive.org/web/20190924163108/https://github.com/microsoft/WSL/issues/107 | title=Missing source code - GPL compliance? · Issue #107 · Microsoft/WSL | url=https://github.com/Microsoft/BashOnWindows/issues/107 | url-status=live | website=GitHub }} | {{ cite web | access-date = 9 April 2016 | archive-date = October 21, 2017 | archive-url = https://web.archive.org/web/20171021004857/http://www.softpedia.com/get/System/System-Miscellaneous/GNU-Bash.shtml | date = January 23, 2010 | publisher = SoftNews | title = GNU Bash | url = http://www.softpedia.com/get/System/System-Miscellaneous/GNU-Bash.shtml | url-status = live | website = [[Softpedia]] }} }}</ref>}} * POSIX-2016 is released by the IEEE.<ref name="POSIX-2016">{{Cite web |title=The Open Group Base Specifications Issue 7, 2016 Edition |url=https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/ |website=pubs.opengroup.org}}</ref> * {{Timeline-event|date={{start date text|September 15, 2016}}|event=Bash 4.4 is released.}} }} {{timeline-item|{{start date|2017}}|2=<nowiki/> * A new version of the POSIX Standard is released.<ref name="POSIX FAQ v 1.18" /> * Some other current operating systems which carry Bash include and [[ArcaOS]].<ref>{{Cite web |title=Compatibility Subsystems |work=Arca Noae |url=https://www.arcanoae.com/wiki/arcaos/compatibility-subsystems/ |url-status=live |archive-url=https://web.archive.org/web/20200923001119/https://www.arcanoae.com/wiki/arcaos/compatibility-subsystems/ |archive-date=September 23, 2020 |access-date=2020-09-04}}</ref> }} {{timeline-item|{{start date|2018}}|2=<nowiki/> * {{Timeline-event|date={{start date text|January 31, 2018}}|event=The IEEE published the POSIX 2017 Standard.<ref name="POSIX-2018">{{Cite web |title=The Open Group Base Specifications Issue 7, 2018 edition |url=https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/ |website=pubs.opengroup.org}}</ref>}} * Apple packaged Bash as their default interactive shell through until macOS Mojave (c.2018). However, for explicit licensing reasons with [[MacOS Catalina|Catalina]]<ref name="scriptingosx.com, Moving to Zsh">{{Cite web |date=5 June 2019 |title=Moving to zsh |url=https://scriptingosx.com/2019/06/moving-to-zsh/?form=MG0AV3}}</ref> (c.2019), Apple replaced its default shell, Bash version 3.2 (c.2006), with [[Z Shell]] version 5.7 (c.2019).<ref name="Apple Support - Use zsh as the default shell on your Mac">{{Cite web |title=Apple Support - Use zsh as the default shell on your Mac |url=https://support.apple.com/en-us/HT208050 |url-status=live |archive-url=https://web.archive.org/web/20191202143802/https://support.apple.com/en-us/HT208050 |archive-date=December 2, 2019 |access-date=1 July 2019}}</ref><ref name="Verge - Apple replaces bash with zsh...">{{Cite web |last=Warren |first=Tom |date=June 4, 2019 |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 |archive-url=https://web.archive.org/web/20190610051842/https://www.theverge.com/2019/6/4/18651872/apple-macos-catalina-zsh-bash-shell-replacement-features |archive-date=June 10, 2019 |access-date=June 13, 2019 |website=The Verge}}</ref> "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."<ref name="scriptingosx.com, Moving to Zsh" /> Zsh uses a more permissive license.<ref name="The Next Web - Why Does MacOS Catalina Use zsh...">{{Cite web |last=Hughes |first=Matthew |date=2019-06-04 |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 |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/ |archive-date=December 31, 2020 |access-date=2021-01-12 |website=The Next Web |language=en-us}}</ref> }} {{timeline-item|{{start date|2019}}|2=<nowiki/> * {{Timeline-event|date={{start date text|January 7, 2019}}|event= Bash 5.0 is released.<ref>{{Cite mailing list |title=Bash-5.0 release available |mailing-list=bug-bash |url=https://lists.gnu.org/archive/html/bug-bash/2019-01/msg00063.html}}</ref>}} }} {{timeline-item|{{start date|2020}}|2=<nowiki/> * With release 2020.4, Kali Linux switched to zsh as its default shell for desktop images, but its ARM, containers, NetHunter and WSL images still use Bash.<ref>{{Cite web |date=18 November 2020 |title=Kali Linux 2020.4 Release (ZSH, Bash, CME, MOTD, AWS, Docs, Win-KeX & Vagrant) | Kali Linux Blog |url=https://www.kali.org/blog/kali-linux-2020-4-release/#zsh-shell-by-default |website=Kali Linux}}</ref> * {{Timeline-event|date={{start date text|December 7, 2020}}|event= Bash 5.1 is released.<ref name="Bash-5.1 release available">{{Cite mailing list |title=Bash-5.1 release available |mailing-list=bug-bash |url=https://lists.gnu.org/archive/html/bug-bash/2020-12/msg00002.html}}</ref>}} }} {{timeline-item|{{start date|2022}}|2=<nowiki/> * {{Timeline-event|date={{start date text|September 26, 2022}}|event=Bash 5.2 is released.<ref>{{Cite mailing list |title=Bash-5.2 Release available |mailing-list=bug-bash |url=https://lists.gnu.org/archive/html/bug-bash/2022-09/msg00056.html}}</ref>}} * "At this point, 2022, a significant number of POSIX compatible or influenced systems exist in servers, cloud computing centers, high performance computers, Apple systems (initially BSD variations), and many cell phone systems. The number of devices measuring into the billions."<ref name="POSIX Impact" /> }} {{timeline-item|{{start date|2023}}|2=<nowiki/> * {{Timeline-event|date={{start date text|September 18, 2023}}|event= [[Windows Subsystem for Linux]] v 2.0.0 is released for [[Windows 11]].<ref name="Github: WSL 2.0.0">{{ GitHub | microsoft/WSL/releases/tag/2.0.0 | Github: WSL 2.0.0 | link=hidden }}</ref><ref name="How to Install WSL on Windows 11">{{Cite web |last=Hoffman |first=Chris |date=July 30, 2021 |title=How to Install the Windows Subsystem for Linux on Windows 11 |url=https://www.howtogeek.com/744328/how-to-install-the-windows-subsystem-for-linux-on-windows-11/ |access-date=2022-10-12 |website=How-To Geek |language=en-US}}</ref> }} }} {{timeline-item|{{start date|2024}}|2=<nowiki/> * {{Timeline-event|date={{start date text|June 14, 2024}}|event=POSIX-2024 is published by the IEEE.}} }} {{timeline-end}} == Features == === List of Short Descriptions === <!-- Suggestion 3 / 8 -- 06 Jan 2025 --> {{prose|date=January 2025}} As a [[Command-line interface|command processor]], Bash can operate in two modes: an interactive and non-interactive mode. In the interactive mode a [[Terminal emulator|text window]] where users input commands to execute various tasks. The second mode, is execution of commands from files, known as [[shell script]]s, facilitating [[automation]]. In keeping with [[Unix shell]] conventions, Bash incorporates a rich set of features, including: * A [https://www.gnu.org/software/bash/manual/index.html User Manual] provided by the GNU Project, also available at <code>info bash</code>, and a technical manual available at <code>man bash</code>. * [[Function (computer programming)|Invocation]] as a... ** [[Interactivity|Interactive]] shell, ** Non-interactive shell, or ** Login shell; * A [[command-line interface]]; * [[Exit status]] codes; * [[Control flow|Control structures]] for ** [[Conditional (computer programming)|Condition testing]], *** <code>if</code>, <code>case</code>, <code>select</code>, *** logical AND (<code>&&</code>) and OR (<code>||</code>), and ** [[Iteration]]: *** <code>for</code>, <code>while</code>, <code>until</code> loops, and *** Arithmetic C-style loop: <code>for ((</code>; * Syntaxes for Boolean testing of file attributes, string and integer values, etc.: ** Traditional <code>test</code> command, ** Traditional single bracket test: <code>[</code>, ** Modern double bracket test: <code> [[ ... ]]</code>, which includes advanced features: *** Extended [[regular expression]] and extglob matching *** Lexicographic sorting with <code><</code> and <code>></code>; * [[Unix|UNIX]]-style [[Pipeline (Unix)|pipelines]]: <code>|</code>; * [[Child process|Subshells]]: <code>$( ... )</code>; * [[Signal (IPC)|Signaling]] as a means of [[inter-process communication]] using the <code>trap</code> builtin; * Asynchronous execution, i.e., [[Job (computing)|Jobs]] and [[Job control (Unix)|job control]]: ** <code>job_spec &</code> where <code>job_spec</code> can be one of: *** A full commandline: <code><command_name> <options> <operands> <arguments> &</code>, or *** A job control identifier as denoted by a leading percent symbol: <code>%1 &</code>; * A shell [[Porting|portability]] mode where command lines can be interpreted in conformance with the [[POSIX terminal interface|POSIX]] standard; * Command parsing: ** Comments are ignored: *** Bourne-style <code>#</code> hashtag comments, and *** Thompson-style <code>:</code> colon comments; ** Commands are parsed one line at a time: *** Control structures are honored, and *** Backslash <code>\</code> escapes are also honored at the ends of lines; ** Split into words (i.e., [[Text segmentation|word splitting]]) according to [[String literal|quoting]] rules, *** Including ANSI-C quoting <code>$'...'</code>; ** Seven kinds of expansions are performed in the following order on the resulting string: *** (Step 1) Brace expansion <code>kernel{-headers}</code>, *** (Step 2) Tilde expansion <code>~</code>, *** (Step 3) In a left-to-right fashion: **** [[Parameter (computer programming)|Parameter]] and [[Variable (computer science)|variable]] expansion <code>$foo</code> or <code>${bar}</code>, including ***** [[Scope (computer science)#Dynamic scoping|Dynamically scoped]] variables, ***** Indexed [[Array (data type)|arrays]] of unlimited size, ***** [[Associative array]]s via <code>declare -A</code>, and ***** Expansion syntaxes which can perform some tasks more quickly than external utilities, including, among others: ****** Pattern Substitution ******* <code>${foo//x/y}</code> for <code>sed 's/x/y/g'</code>, ****** Remove Matching Prefix or Suffix Pattern ******* <code>${bar##[a-zA-Z0-9]*}</code> for <code>cut -c8-</code>, ****** Print Array Keys ******* <code>${!array[@]}</code>, and ****** Display Error if Null or Unset ******* <code>${var:?error message}</code>, **** [[Command substitution]]: <code>$( ... )</code>, **** [[Process substitution]], <code><()</code> or <code>>()</code>, when a system supports it: **** Arithmetic expansion, <code>(( ... ))</code> or <code>$(( ... ))</code>, 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)|<code>bc</code>]] and [[AWK|<code>awk</code>]], among others), *** (Step 4) [[Text segmentation|Word splitting]] (again), *** (Step 5) Pathname expansion, i.e., shell-style [[Glob (programming)|globbing]] and [[pattern matching]] using <code>*</code>, <code>?</code>, <code>[...]</code>, and **** (Although they can be used in conjunction, the use of brackets in pattern matching, <code>[...]</code>, and the use of brackets in the testing commands, <code>[</code> and <code> [[ ... ]]</code>, are each one different things.) *** [[String literal|Quote]] removal; ** [[Redirection (computing)|Redirections]] of Standard Input, Standard Output and Standard Error [[Standard streams|data streams]] are performed, including *** File writing, <code>></code>, and appending, <code>>></code>, *** [[Here document]]s, <code><<</code>, *** Here strings, <code><<<</code>, which allow parameters to be used as input, and *** A redirection operator, <code>>|</code>, which can force overwriting of a file when a shell's "noclobber" setting is enabled; ** 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</code>]] or [[Ln (Unix)|<code>ln</code>]], and **** [[Shell script]]s, which are [[File system|files]] containing executable commands. (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. Bash also offers... * Configurable execution environment(s):<ref>{{Cite web |title=Command Execution Environment (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Command-Execution-Environment.html |website=www.gnu.org}}/</ref> ** Shell and [[Session (computer science)|session]] startup files such as <code>~/.bashrc</code> and <code>~/.profile</code> (i.e., [[Hidden file and hidden directory|dotfiles]]); ** Settings (<code>set</code> [[Shell builtin|built-in]]) and shell options (<code>shopt</code> [[Shell builtin|built-in]]) which alter shell behavior; * Support for [[Unicode]]; * With interactive invocation only, ** Unlimited size [[command history]], ** A directory stack (see <code>pushd</code> and <code>popd</code> built-ins), ** [[Command-line completion|Tab completion]], ** Configurable [[Command-line interface#Command prompt|prompts]], and ** Command line editing with [[GNU Readline|GNU readline]]; * Lightweight [[Logging (computing)|logging]] for [[debugging]] purposes (xtrace), and other lightweight debugging options (errexit, noexec, nounset, pipefail, etc.); * Shell [[compatibility mode]]s: bash 5.1 can operate as if it were bash 4.2, etc.; * Various Built-In Commands: ** <code>cd</code> ** <code>pwd</code> * Documentation: ** A built-in <code>help</code> command. ** A [[man page]], and ** An [[Info (Unix)|info page]] which is the same as the GNU manual; * Informal avenues of support via: ** IRC at libera.chat #bash ** Mailing lists at [https://www.gnu.org/software/bash/ Bash - GNU Project - Free Software Foundation] ===General Discussion=== The Bash [[command (computing)|command]] syntax is a [[superset]] of the Bourne shell command syntax. Bash supports [[brace expansion]],<ref>{{Cite web |title=Brace Expansion (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html |archive-url=https://web.archive.org/web/20180315115230/http://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion |archive-date=March 15, 2018 |access-date=2024-01-10 |website=www.gnu.org }}</ref> [[command line completion]] (Programmable Completion),<ref>{{Cite web |title=Bash Reference Manual: Programmable Completion |url=https://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion |website=[[GNU Project]] }}</ref> basic debugging<ref>{{Cite web |title=Debugging Bash scripts |url=http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html |url-status=live |archive-url=https://web.archive.org/web/20181104185300/http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html |archive-date=November 4, 2018 |access-date=November 20, 2018 |website=tldp.org }}</ref><ref>{{Cite web |title=The Set Builtin (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html |access-date=2024-01-10 |website=www.gnu.org }}</ref> and [[Signal (IPC)|signal handling]] (using <code>trap</code>) since bash 2.05a<ref>{{Cite web |title=Bash changes [Bash Hackers Wiki (DEV 20200708T2203)] |url=https://wiki-dev.bash-hackers.org/scripting/bashchanges |url-status=live |archive-url=https://web.archive.org/web/20190923203509/https://wiki-dev.bash-hackers.org/scripting/bashchanges |archive-date=September 23, 2019 |access-date=September 23, 2019 |website=wiki-dev.bash-hackers.org }}</ref><ref>{{Cite web |title=Bourne Shell Builtins (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html |access-date=2024-01-10 |website=www.gnu.org }}</ref> among other features. Bash can execute the vast majority of Bourne shell scripts 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 [[KornShell|Korn Shell]] (ksh) and the [[C shell]] (csh) such as command line editing, [[command history]] (<code>history</code> command),<ref>{{Cite web |title=Bash Reference Manual |url=https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Bash-History-Builtins |url-status=live |archive-url=https://web.archive.org/web/20190915123105/http://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Bash-History-Builtins |archive-date=September 15, 2019 |access-date=September 15, 2019 |website=www.gnu.org }}</ref> the directory stack, the <code>$RANDOM</code> and <code>$PPID</code> variables, and POSIX [[command substitution]] syntax <code>$(...)</code>. When a user presses the [[tab key]] within an interactive command-shell, Bash automatically uses [[command line completion]], since beta version 2.04,<ref name="auto1">{{Cite web |title=Working more productively with bash 2.x/3.x |url=http://www.caliban.org/bash/index.shtml |url-status=live |archive-url=https://web.archive.org/web/20180629230903/http://www.caliban.org/bash/index.shtml |archive-date=June 29, 2018 |access-date=June 21, 2018 |website=www.caliban.org }}</ref> 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. Bash's syntax has many extensions lacking in the Bourne shell. Bash can perform integer calculations ("arithmetic evaluation") without spawning external processes. It uses the <code>((...))</code> command and the <code>$((...))</code> variable syntax for this purpose. 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>&></code> operator. This is simpler to type than the Bourne shell equivalent '<code>command > file 2>&1</code>'. Bash supports [[process substitution]] using the <code><(command)</code> and <code>>(command)</code>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). When using the 'function' keyword, Bash function declarations are not compatible with Bourne/Korn/POSIX scripts (the KornShell 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. Because of 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, Bash conforms with POSIX more closely.<ref name="GNUBASHREF">{{Citation |title=The GNU Bash Reference Manual, for Bash, Version 4.1 |date=December 23, 2009 |url=https://www.gnu.org/software/bash/manual/html_node/index.html |access-date=October 26, 2010 |archive-url=https://web.archive.org/web/20101203065400/https://www.gnu.org/software/bash/manual/html_node/index.html |archive-date=December 3, 2010 |url-status=live |chapter=6.11 Bash POSIX Mode |chapter-url=https://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html }}</ref> Bash supports [[here document]]s. Since version 2.05b Bash can redirect [[Stdin|standard input]] (stdin) from a "here string" using the <code><<<</code> operator. Bash 3.0 supports in-process [[regular expression]] matching using a syntax reminiscent of [[Perl]].<ref>{{Cite web |title=Advanced Bash-Scripting Guide |url=http://www.tldp.org/LDP/abs/html/bashver3.html#BASH3REF |url-status=live |archive-url=https://web.archive.org/web/20170505161903/http://tldp.org/LDP/abs/html/bashver3.html#BASH3REF |archive-date=May 5, 2017 |access-date=2017-03-05 |website=www.tldp.org |at=Section 37.2 (Bash, version 3) }}</ref> In February 2009,<ref>{{Cite web |title=Bash, version 4 |url=http://tldp.org/LDP/abs/html/bashver4.html |url-status=live |archive-url=https://web.archive.org/web/20180701001653/http://www.tldp.org/LDP/abs/html/bashver4.html |archive-date=July 1, 2018 |access-date=June 25, 2018 |website=tldp.org }}</ref> Bash 4.0 introduced support for [[associative arrays]].<ref name="bashfaq061" /> Associative array indices are strings, in a manner similar to [[AWK]] or [[Tcl]].<ref>{{Cite web |title=Arrays (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Arrays.html |url-status=live |archive-url=https://web.archive.org/web/20180711142941/http://www.gnu.org/software/bash/manual/html_node/Arrays.html |archive-date=July 11, 2018 |access-date=July 4, 2018 |website=www.gnu.org }}</ref> They can be used to emulate multidimensional arrays. Bash 4 also switches its license to [[GNU General Public License#Version 3|GPL-3.0-or-later]].<ref>{{Cite web |title=macos - 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 |archive-url=https://web.archive.org/web/20180625213216/https://apple.stackexchange.com/questions/193411/update-bash-to-version-4-0-on-osx |archive-date=June 25, 2018 |access-date=June 25, 2018 |website=Ask Different }}</ref> <!-- === Exit Codes === --> === Control Structures === <!-- '''+++ <code>if</code>''' '''+++ <code>case</code>''' '''+++ <code>for</code>''' '''+++ <code>for ((</code>''' '''+++ <code>while</code> and <code>until</code>''' '''+++ <code>&&</code> and <code>||</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="bash"> cd "$SOMEWHERE" && ./do_something || echo "An error occurred" >&2 </syntaxhighlight> Where {{code|./do_something}} is only executed if the {{code|cd}} (change directory) command was "successful" (returned an exit status of zero) and the {{code|echo}} command would only be executed if either the {{code|cd}} or the {{code|./do_something}} command return an "error" (non-zero exit status). For all commands the exit status is stored in the special variable <code>$?</code>. Bash also supports {{code|2=bash|if ...;then ...;else ...;fi}} and {{code|2=bash|case $VARIABLE in $pattern)...;;$other_pattern)...;; esac}} forms of conditional command evaluation. <!-- === Boolean Testing === '''+++ <code>test</code> Built-In and Binary''' '''+++ Single Bracket <code>[</code> Built-In and Binary''' '''+++ Double Bracket <code>[[</code> Built-In (and no Binary)''' --><!-- === Pipelines === --><!-- === Subshells === '''+++ Standard Subshells <code>(...)</code>''' '''+++ Command Substitutions <code>$(...)</code>''' '''+++ Pipelines (again) <code>| ... |</code>''' --><!-- === Signals === --> === Process Management (a.k.a., "Job control") === 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 ";", or on separate lines: <syntaxhighlight lang="bash"> command1; command2 command3 </syntaxhighlight> In this example, when command1 is finished, command2 is executed, and when command2 has completed, command3 will execute. A [[Background process|background execution]] of command1 can occur using (symbol &) 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="bash">command1 &</syntaxhighlight> Or to have a concurrent execution of command1 and command2, they must be executed in the Bash shell in the following way: <syntaxhighlight lang="bash"> command1 & command2 </syntaxhighlight> In this case command1 is executed in the background ''&'' symbol, returning immediately control to the shell that executes 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 |title=Bash Reference Manual |url=https://www.gnu.org/software/bash/manual/bash.html#index-background |url-status=live |archive-url=https://web.archive.org/web/20180315115230/http://www.gnu.org/software/bash/manual/bash.html#index-background |archive-date=March 15, 2018 |access-date=March 27, 2018 |website=www.gnu.org }}</ref> A list of all processes, both in the background and stopped, can be achieved by running <code>jobs</code>: <syntaxhighlight lang="console"> $ jobs [1]- Running command1 & [2]+ Stopped command2 </syntaxhighlight> In the output, the number in brackets refers to the job id. The plus sign signifies the default process for <code>bg</code> and <code>fg</code>. 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 <code>fg</code> command brings a process to the foreground, while <code>bg</code> sets a stopped process running in the background. <code>bg</code> and <code>fg</code> 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 <code>jobs</code>. The <code>[[Kill (command)|kill]]</code> 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="bash"> kill %1 </syntaxhighlight> === Portability with POSIX === Invoking Bash with the <code>--posix</code> option or stating <code>set -o posix</code> in a script causes Bash to conform very closely with the [[Posix#POSIX.2|POSIX 1003.2 standard]].<ref name="tldp">{{Cite web |last=Mendel Cooper |title=Portability Issues |url=http://tldp.org/LDP/abs/html/portabilityissues.html |url-status=live |archive-url=https://web.archive.org/web/20120127105451/http://tldp.org/LDP/abs/html/portabilityissues.html |archive-date=January 27, 2012 |access-date=January 26, 2012 |website=The Linux Documentation Project |publisher=ibiblio.org }}</ref> Bash shell scripts intended for [[portability (computer science)|portability]] should take into account at least the POSIX shell standard. Some bash features not found in POSIX are:<ref name="tldp" /><ref name="deb">{{Cite web |title=10. Files |url=https://www.debian.org/doc/debian-policy/ch-files.html#scripts |url-status=live |archive-url=https://web.archive.org/web/20200512050159/https://www.debian.org/doc/debian-policy/ch-files.html#scripts |archive-date=May 12, 2020 |access-date=May 11, 2020 |website=Debian Policy Manual v4.5.0.2 }}</ref> {{div col start}} * Certain extended invocation options * Brace expansion * Arrays and associative arrays * The double bracket {{code| [[...]] }} extended test construct and its regex matching * The double-parentheses arithmetic-evaluation construct (only {{code|(( ... ))}}; {{code|$(( ... ))}} is POSIX) * Certain string-manipulation operations in parameter expansion * {{code|local}} for scoped variables * Process substitution * Bash-specific builtins * [[Coprocess]]es * $EPOCHSECONDS and $EPOCHREALTIME variables<ref>{{Cite web |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 |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 |archive-date=June 3, 2020 |access-date=June 3, 2020 |website=Shell Tips! }}</ref> {{div col end}} If a piece of code uses such a feature, it is called a "bashism" – a problem for portable use. Debian's {{code|checkbashisms}} and Vidar Holen's {{code|shellcheck}} can be used to make sure that a script does not contain these parts.<ref name="checkbashisms, ManKier man page">{{man|1|checkbashisms|ManKier}}</ref><ref name="shellcheck, ManKier man page">{{man|1|shellcheck|ManKier}}</ref> The list varies depending on the actual target shell: Debian's policy allows some extensions in their scripts (as they are in the [[Almquist shell#Dash|dash]] shell),<ref name=deb/> while a script intending to support pre-POSIX Bourne shells, like [[autoconf]]'s {{code|configure}}, are even more limited in the features they can use.<ref>{{Cite web |title=Portable Shell |url=https://www.gnu.org/software/autoconf/manual/html_node/Portable-Shell.html |url-status=live |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 |archive-date=March 2, 2021 |access-date=20 January 2020 |website=Autoconf }}</ref> <!-- === Comments === === Word Splitting & Quoting === '''+++ Backslash <code>\</code>''' '''+++ Double Quotes <code>"..."</code>''' '''+++ Single Quotes <code>'...'</code>''' '''+++ ANSI-C Quoting <code>$'...'</code>''' --> === Brace Expansion === Brace expansion, also called alternation, is a feature copied from the [[C shell]]. It generates a set of alternative combinations. 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 <code>eval</code> 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 === --><!-- === Parameter and Variable Expansion === '''+++ Attributes''' '''+++ Scalar Variables''' '''+++ Array Variables''' '''++++++ Indexed Arrays''' '''++++++ Associative Arrays''' '''+++ Shell Variables''' '''++++++ Positional Parameters''' '''++++++ Special Variables''' '''++++++ POSIX Variables''' '''++++++ Non-POSIX Variables''' '''+++ <code>export</code> and Environment Variables''' --><!-- === Command Substitution (again) === '''+++ Modern <code>$(...)</code>''' '''+++ Deprecated <code>`...`</code>''' --><!-- === Process Substitution (again) === '''+++ <code><(...)</code> and <code>>(...)</code>''' --><!-- === Arithmetic Expansion === '''+++ <code>((..))</code>''' '''+++ <code>$((...))</code>''' '''+++ Other Arithmetic Contexts''' '''+++ Integer Variables''' --><!-- === Redirections === '''+++ Standard''' '''+++ Here Documents''' '''+++ Here Strings''' --><!-- === Aliases === --><!-- === Reserved Words and Grammar === --><!-- === Functions === --><!-- === Built-Ins === --><!-- === Command Lookup === --> === Configurable execution environment(s) === ==== Shell and Session Startup Files (a.k.a., "Dot Files") ==== <!-- Suggestion 4 / 8 -- 06 Jan 2025 --> {{ How-to section | date=January 2019 }} When Bash starts, it executes the commands in a variety of [[Hidden file and hidden directory#Unix and Unix-like environments|dot files]].<ref>{{Cite web |title=I Almost Get a Linux Editor and Compiler |url=http://www.drdobbs.com/i-almost-get-a-linux-editor-and-compiler/184404693 |url-status=live |archive-url=https://web.archive.org/web/20210302212410/https://www.drdobbs.com/i-almost-get-a-linux-editor-and-compiler/184404693 |archive-date=March 2, 2021 |access-date=2020-09-12 |website=Dr. Dobb's |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. }}</ref> Unlike Bash shell scripts, dot files do typically have neither the execute permission enabled nor an [[interpreter directive]] like <code>#!/bin/bash</code>. ===== Legacy-compatible Bash startup example ===== The example <code>~/.bash_profile</code> below is compatible with the Bourne shell and gives semantics similar to csh for the <code>~/.bashrc</code> and <code>~/.bash_login</code>. 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>&&</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</code> 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</code> or <code>~/.xprofile</code> file to read the <code>~/.profile</code> — which provides the environment variables that Bash shell windows spawned from the window manager need, such as [[xterm]] or [[Gnome Terminal]]. ==== Settings and Shell Options ==== ===== The <code>set</code> Built-in ===== * Xtrace: [ <code>set -x</code> | <code>set -o xtrace</code> ] The shell's primary means of debugging. Both xtrace and verbose can be turned off at the same time with the command <code>set -</code>. * Verbose: [ <code>set -v</code> | <code>set -o verbose</code> ] 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</code> 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 |mailing-list=bug-bash |date=20 April 2021 |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 -</code>. ===== The <code>shopt</code> Built-in ===== * expand-aliases On by default in interactive shells. Some developers discourage its use in scripts. <!-- === Localization === '''+++ Environment Variables beginning with <code>LC_*</code> ''' '''+++ Locale-specific Expansion <code>$"..."</code>''' --><!-- === Reporting the Time === '''+++ <code>SECONDS</code>, <code>EPOCHSECONDS</code> and <code>EPOCHREALTIME</code>''' '''+++ The <code>printf</code> Builtin (and not the Binary)''' '''+++ The <code>date</code> Binary and <code>LC_TIME</code>''' --><!-- === Command History === --><!-- === Tab Completion === --> === Programmable Completion === Bash supports programmable [[Command-line completion|completion]] via built-in <code>complete</code>, {{Code|compopt}}, and <code>compgen</code> commands.<ref>{{Cite web |title=Bash Reference Manual |url=https://tiswww.case.edu/php/chet/bash/bashref.html#Programmable-Completion |website=tiswww.case.edu }}</ref> The feature has been available since the beta version of 2.04 released in 2000.<ref name="auto1"/><ref>{{Cite web |title=Index of /gnu/bash |url=https://ftp.swin.edu.au/gnu/bash/ |url-status=live |archive-url=https://web.archive.org/web/20200308104032/http://ftp.swin.edu.au/gnu/bash/ |archive-date=March 8, 2020 |access-date=September 15, 2019 |website=ftp.swin.edu.au }}</ref> These commands enable complex and intelligent completion specification for commands (i.e. installed programs), functions, variables, and filenames.<ref name=":1">{{Cite web |title=An Introduction to Programmable Completion |url=https://tldp.org/LDP/abs/html/tabexpansion.html |access-date=2022-01-21 |website=tldp.org }}</ref> The <code>complete</code> 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 {{Key|tab}} keystroke after typing its name.<ref name=":1" /> <!-- === Shell-native Pattern Matching === '''+++ Wildcards (a.k.a., "Globs"): <code>*</code> <code>[...]</code> and <code>?</code>''' '''+++ Pattern Matching Contexts''' --><!-- === Regular Expressions === '''+++ The Regex Operator (<code>=~</code>) of the Double Bracket Keyword (<code>[[</code>)''' '''+++ <code>BASH_REMATCH</code>''' --><!-- === Coprocesses === --> === Keyboard shortcuts with Readline === {{ Main | GNU Readline }} Bash uses [[GNU Readline]] to provide keyboard shortcuts for command line editing using the default ([[Emacs]]) key bindings. [[Vi-binding]]s can be enabled by running <code>set -o vi</code>.<ref>{{Cite web |date=October 5, 2012 |title=BASH Help - A Bash Tutorial |url=http://www.hypexr.org/bash_tutorial.php#emacs |url-status=live |archive-url=https://web.archive.org/web/20210302213519/http://www.hypexr.org/bash_tutorial.php#emacs |archive-date=March 2, 2021 |access-date=July 21, 2013 |publisher=Hypexr.org }}</ref> <!-- === Observability === '''+++ <code>set</code> and <code>env</code>''' '''+++ <code>getconf</code>''' '''+++ <code>compgen</code>''' '''+++ Exit Codes (again?)''' '''+++ Xtrace and Verbose Modes''' --><!-- === Programming Paradigm === --> == Documentation == As the standard upon which bash is based, the POSIX Standard, or IEEE Std 1003.1,<ref>{{Cite web |title=The Open Group Base Specifications Issue 7, 2018 edition |url=https://pubs.opengroup.org/onlinepubs/9699919799/ |website=pubs.opengroup.org }}</ref> et seq, is especially informative. The Linux "man page"<ref>{{Cite web |title=BASH(1) Manual Page |url=https://tiswww.case.edu/php/chet/bash/bash.html |website=tiswww.case.edu }}</ref><ref>{{Cite web |title=bash.0\doc - bash.git - bash |url=https://git.savannah.gnu.org/cgit/bash.git/tree/doc/bash.0 |website=git.savannah.gnu.org }}</ref> is intended to be the authoritative explanatory technical document for the understanding of how <code>bash</code> operates. It is usually available by running <code>man bash</code>. The GNU [https://www.gnu.org/software/bash/manual/index.html manual] is sometimes considered more user-friendly for reading. "You may also find information about Bash by running <code>info bash</code> ... or by looking at <code>/usr/share/doc/bash/</code>, <code>/usr/local/share/doc/bash/</code>, or similar directories on your system. A brief summary is available by running <code>bash --help</code>.<ref name="auto">{{Cite web |title=Bash - GNU Project - Free Software Foundation |url=https://www.gnu.org/savannah-checkouts/gnu/bash/bash.html |access-date=2024-01-10 |website=www.gnu.org }}</ref> " If a user invoke RUNCOM without any arguments it prints some instructions on how to use it and stops, returning the user to the supervisor's (system's) command line.([[RUNCOM]])" On modern Linuxes, information on shell built-in commands can be found by executing <code>help</code>, <code>help [built-in name]</code> or <code>man builtins</code> at a terminal prompt where bash is installed. Some commands, such as <code>echo</code>, <code>false</code>, <code>kill</code>, <code>printf</code>, <code>test</code> or <code>true</code>, depending on your system and on your locally installed version of bash, can refer to either a shell built-in or a system binary executable file. When one of these command name collisions occurs, bash will by default execute a given command line using the shell built-in. Specifying a binary executable's absolute path (i.e., <code>/bin/printf</code>) is one way of ensuring that the shell uses a system binary. This name collision issue also effects any "help summaries" viewed with <code>kill --help</code> and <code>/bin/kill --help</code>. Shell built-ins and system binary executable files of the same name often have differing options. "The project maintainer also has a Bash page which includes Frequently Asked Questions",<ref>{{multiref| {{Cite web |title=The GNU Bourne-Again Shell |url=https://tiswww.case.edu/php/chet/bash/bashtop.html |website=tiswww.case.edu }} | {{ cite web | title = Frequently Asked Questions | url = https://tiswww.case.edu/php/chet/bash/FAQ | website = tiswww.case.edu }} }}</ref><ref name="auto" /> this FAQ is current as of bash version 5.1 and is no longer updated. == Security and Vulnerabilities == === 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}/</code>, but the variable <code>$dir</code> 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 /</code> 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 <code>sudo</code> on a per-command basis instead. === Debugging === <!-- Beginning of Table --> <!-- Headers --> {| Table | sort | class="wikitable sortable" style="font-size: smaller;" |+ Bash features which can be useful during debugging. |- ! 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 |- <!-- Data --> | align=left | Parameter Expansions || Indicate Null or Unset | align=left | {{code|"${parameter:?[word]}"|bash}} | {{yes}} | align=left | "Where the expansion of [word], perhaps an error message or a line number, is written to STDERR and the shell exits with a non-zero exit code." | {{dunno}} |- | align=left | Special Parameters || Exit Status | align=left | {{code|"$?"|bash}} | {{yes}} | align=left | "Expands to the shortest representation of the decimal exit status." | {{dunno}} |- | align=left | Special Parameters || PID of Invoked Shell | align=left | {{code|"$$"|bash}} | {{yes}} | align=left | "Expands to the shortest representation of the decimal process ID of the invoked shell." | {{dunno}} |- | align=left | Special Built-In Utility || set :: xtrace | align=left | {{code|set -x|bash}} | {{yes}} | 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}} |- | align=left | Special Built-In Utility || set :: verbose | align=left | {{code|set -v|bash}} | {{yes}} | align=left | "Writes its input to standard error as it is read." | {{dunno}} |- | align=left | Special Built-In Utility || set :: pipefail | align=left | {{code|set -o pipefail|bash}} | {{yes}} | 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}} |- | align=left | Special Built-In Utility || set :: nounset | align=left | {{code|set -u|bash}} | {{yes}} | 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}} |- | align=left | Special Built-In Utility || set :: errexit | align=left | {{code|set -e|bash}} | {{yes}} | 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 considered 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}} |- | align=left | Special Built-In Utility || trap :: EXIT | align=left | {{code|trap '[arg]' EXIT|bash}} | {{yes}} | align=left | "If a [sigspec] (signal specifier) is 0 or EXIT, [arg] is executed when the shell exits." If [arg] contains expansions, then [arg] should be in single quotes. | {{dunno}} |- | align=left | Utility || printf | align=left | {{code|printf '<%s>\n' "${var}"|bash}} | {{yes}} | align=left | A means of reliably printing the contents of a variable. | {{dunno}} |- | align=left | Bash Variables || BASHPID | align=left | {{code|"${BASHPID}"|bash}} | {{no}} | align=left | "Expands to the process ID of the current bash process."<ref>{{Cite web |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASHPID |website=www.gnu.org |id=BASHPID}}</ref> | {{dunno}} |- | align=left | Bash Variables || BASH_ARGC | align=left | {{code|"${BASH_ARGC[@]}"|bash}} | {{no}} | 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 |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fARGC |website=www.gnu.org |id=BASH_ARGC}}</ref> | {{dunno}} |- | align=left | Bash Variables || BASH_ARGV | align=left | {{code|"${BASH_ARGV[@]}"|bash}} | {{no}} | align=left | "An array variable containing all of the parameters in the current bash execution call stack."<ref>{{Cite web |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fARGV |website=www.gnu.org |id=BASH_ARGV}}</ref> | {{dunno}} |- | align=left | Bash Variables || BASH_LINENO | align=left | {{code|"${BASH_LINENO[@]}"|bash}} | {{no}} | align=left | "An array variable whose members are the line numbers in source files where each corresponding member of FUNCNAME was invoked."<ref>{{Cite web |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fLINENO |website=www.gnu.org |id=BASH_LINENO}}</ref> | {{dunno}} |- | align=left | Bash Variables || BASH_REMATCH | align=left | {{code|"${BASH_REMATCH[@]}"|bash}} | {{no}} | align=left | "An array variable whose members are assigned by the =~ binary operator to the <nowiki>[[</nowiki> conditional command."<ref>{{Cite web |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fREMATCH |website=www.gnu.org |id=BASH_REMATCH}}</ref> | {{dunno}} |- | align=left | Bash Variables || BASH_SOURCE | align=left | {{code|"${BASH_SOURCE}"|bash}} | {{no}} | align=left | "An array variable whose members are the source filenames where the corresponding shell function names in the FUNCNAME array variable are defined."<ref>{{Cite web |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fSOURCE |website=www.gnu.org |id=BASH_SOURCE}}</ref> | {{dunno}} |- | align=left | Bash Variables || BASH_XTRACEFD | align=left | {{code|"${BASH_XTRACEFD}"|bash}} | {{no}} | align=left | "If set to an integer corresponding to a valid file descriptor, Bash will write the trace output generated when ‘set -x’ is enabled to that file descriptor."<ref>{{Cite web |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fXTRACEFD |website=www.gnu.org |id=BASH_XTRACEFD}}</ref> | {{dunno}} |- | align=left | Bash Variables || EPOCHREALTIME | align=left | {{code|"${EPOCHREALTIME}"|bash}} | {{no}} | align=left | "Each time this parameter is referenced, it expands to the number of seconds since the Unix Epoch (see time(3)) as a floating point value with micro-second granularity."<ref>{{Cite web |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-EPOCHREALTIME |website=www.gnu.org |id=EPOCHREALTIME}}</ref> | {{dunno}} |- | align=left | Bash Variables || FUNCNAME | align=left | {{code|"${FUNCNAME[@]}"|bash}} | {{no}} | align=left | "An array variable containing the names of all shell functions currently in the execution call stack."<ref>{{Cite web |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-FUNCNAME |website=www.gnu.org |id=FUNCNAME}}</ref> | {{dunno}} |- | align=left | Bash Variables || LINENO | align=left | {{code|"${LINENO}"|bash}} | {{no}} | 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 |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-LINENO |website=www.gnu.org |id=LINENO}}</ref> | {{dunno}} |- | align=left | Bash Variables || PIPESTATUS | align=left | {{code|"${PIPESTATUS[@]}"|bash}} | {{no}} | 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 |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-PIPESTATUS |website=www.gnu.org |id=PIPESTATUS}}</ref> | {{dunno}} |- | align=left | Bash Variables || PPID | align=left | {{code|"${PPID}"|bash}} | {{no}} | align=left | "The process ID of the shell's parent."<ref>{{Cite web |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-PPID |website=www.gnu.org |id=PPID}}</ref> | {{dunno}} |- | align=left | Bash Variables || PS4 | align=left | {{code|"${PS4}"|bash}} | {{no}} | 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 |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-PS4 |website=www.gnu.org |id=PS4}}</ref> | {{dunno}} |- | align=left | Shell Builtin || set :: restricted | align=left | {{code|set -r|bash}} | {{no}} | 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}} |- | align=left | Shell Builtin || shopt :: extdebug | align=left | {{code|shopt -s extdebug|bash}} | {{no}} | align=left | "Behavior intended for use by debuggers." | {{dunno}} |- | align=left | Shell Builtin || trap :: DEBUG | align=left | {{code|trap '[arg]' DEBUG|bash}} | {{no}} | align=left | "If a sigspec is DEBUG, the command arg is executed before" certain kinds of commands. | {{dunno}} |- | align=left | Shell Builtin || trap :: ERR | align=left | {{code|trap '[arg]' ERR|bash}} | {{no}} | 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}} |- | align=left | Shell Builtin || trap :: RETURN | align=left | {{code|trap '[arg]' RETURN|bash}} | {{no}} | align=left | "If a sigspec is RETURN, the command arg is executed each time a shell function or a script executed with the. or source builtins finishes executing." | {{dunno}} <!-- Format of table entries |- | align=left | foo || | align=left | {{code|bar|bash}} | align=center | | align=left | | {{dunno}} --> |} <!-- End of Table --> <!-- Kinds of references --> <!-- [[Solaris (operating system)#Traditional operating system license (1992 to 2004)|Traditional license]] --> <!-- ! colspan = 1 rowspan = 2 | End of support<ref>{{Cite web |title=Lifetime Support Policies, see Oracle and Sun System Software and Operating Systems (PDF) |url=http://www.oracle.com/us/support/lifetime-support/index.html |url-status=live |archive-url=https://web.archive.org/web/20130429180633/http://www.oracle.com/us/support/lifetime-support/index.html |archive-date=April 29, 2013 |access-date=April 18, 2013 |publisher=Oracle Corporation }}</ref> --> * Shell features specified by [[POSIX]]: ** Parameter Expansions:<ref>{{multiref| [https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html GNU Bash Manual, 3.5.3 Shell Parameter Expansion]| [https://tiswww.case.edu/php/chet/bash/bash.html#lbBB bash(1), Parameter Expansion]| [https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_06_02 POSIX 2024, 2.6.2 Parameter Expansion]}}</ref> ** Special Parameters:<ref name="GNU Bash Manual, 3.4.2 Special Parameters">{{Cite web |title=Special Parameters (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html |website=www.gnu.org}}</ref><ref name="POSIX 2024, 2.5.2 Special Parameters">{{Cite web |title=Shell Command Language |url=https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_05_02 |website=pubs.opengroup.org}}</ref> ** Special Built-In Utility {{code|set|bash}}:<ref name="the_set">{{multiref| [https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html GNU Bash Manual, 4.3.1 The Set Builtin]|[https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_26 POSIX 2024, set]}}</ref><ref name="bash(1), SHELL BUILTIN COMMANDS">{{Cite web |title=BASH(1) Manual Page |url=https://tiswww.case.edu/php/chet/bash/bash.html#lbDB |website=tiswww.case.edu}}</ref> ** Special Built-In Utility {{code|trap [-lp] [arg] [sigspec …]|bash}}:<ref name="GNU Bash Manual, 4.1 Bourne Shell Builtins: trap">{{Cite web |title=Bourne Shell Builtins (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html#index-trap |website=www.gnu.org}}</ref><ref name="bash(1), SHELL BUILTIN COMMANDS" /> ** Utility {{code|printf|bash}}: a means of reliably printing the contents of a variable: * Bash features not specified by POSIX: ** Bash Variables:<ref name="GNU Bash Manual, 5.2 Bash Variables">{{Cite web |title=Bash Variables (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html |website=www.gnu.org}}</ref><ref name="bash(1): Shell Variables">{{Cite web |title=BASH(1) Manual Page |url=https://tiswww.case.edu/php/chet/bash/bash.html#lbAW |website=tiswww.case.edu}}</ref> ** Shell Builtin {{code|set|bash}}:<ref name="the_set" /><ref name="bash(1), SHELL BUILTIN COMMANDS" /> ** Shell Builtin {{code|shopt|bash}}:<ref name="GNU Bash Manual, 4.3.2 The Shopt Builtin">{{Cite web |title=The Shopt Builtin (Bash Reference Manual) |url=https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html |website=www.gnu.org}}</ref><ref name="bash(1), SHELL BUILTIN COMMANDS" /> ** Shell Builtin {{code|trap [-lp] [arg] [sigspec …]|bash}}:<ref name="GNU Bash Manual, 4.1 Bourne Shell Builtins: trap" /><ref name="bash(1), SHELL BUILTIN COMMANDS" /> While POSIX does specify certain uses of the {{code|trap|bash}} builtin, the following signal specs are Bash extensions. * Third party debugging utilities: ** ShellCheck: Shell script analysis tool;<ref name="ShellCheck">{{multiref2| [https://shellcheck.net ShellCheck: Shell script analysis tool]|{{GitHub|koalaman/shellcheck|Github: shellcheck|link=hidden}}}}</ref><ref name="shellcheck, ManKier man page" /> ** devscripts-checkbashisms: Check whether a /bin/sh script contains any common bash-specific constructs;<ref name="Package: devscripts: scripts to make the life of a Debian Package maintainer easier">{{Cite web |title=Debian -- Details of package devscripts in sid |url=https://packages.debian.org/sid/devscripts |website=packages.debian.org}}</ref><ref name="checkbashisms, ManKier man page" /> ** kcov: Code coverage tool without special compilation options;<ref name="Kcov - code coverage">[https://simonkagstrom.github.io/kcov Kcov - code coverage]</ref> ** Bashdb: The Bash symbolic debugger.<ref name="Debugging with the BASH debugger">{{Cite web |title=BASH Debugger |url=https://bashdb.sourceforge.net/bashdb.html |website=bashdb.sourceforge.net}}</ref><ref name="Documentation of Project Homepage">{{Cite mailing list |title=[Bashdb-devel] Re: [PATCH] fix bashdb script handling of tmp directory |mailing-list=bug-bash |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|:?|bash}} parameter expansion, an unset or null variable can halt a script. * ex.sh *: <syntaxhighlight lang="bash"> #!/bin/bash bar="foo is not defined" echo "${foo:?$bar}" echo this message doesn't print </syntaxhighlight> *: <syntaxhighlight lang="console"> $ ./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 in Bash, the number of spaces before the newline is made clear. : <syntaxhighlight lang="console"> $ # In POSIX shell: $ array=( "a" "b" " > c " ) $ printf ',%s,\n' "${array[@]}" ,a, , b, , c, </syntaxhighlight> : <syntaxhighlight lang="bash"> # In Bash: declare -p array declare -a array=([0]="a" [1]=" b" [2]=$' \n c ') </syntaxhighlight> Printing an error message when there's a problem. * error.sh *: <syntaxhighlight lang="bash"> if ! lsblk | grep sdb then echo Error, line $LINENO fi </syntaxhighlight> *: <syntaxhighlight lang="console"> $ ./error.sh Error, line 130 </syntaxhighlight> Using [[xtrace]]. If errexit had been enabled, then {{code|echo quux|bash}} would not have been executed. * test.sh *: <syntaxhighlight lang="bash"> #!/bin/bash set -x foo=bar; echo $foo false echo quux </syntaxhighlight> *: <syntaxhighlight lang="console"> $ ./test.sh + foo=bar + echo bar bar + false + echo quux quux </syntaxhighlight> === Deprecated syntax === * Back-tick style command substitutions: <code>`...`</code> is deprecated in favor of <code>$(...)</code>; * Use of -a or -o in <code>test</code>/<code>[</code>/<code>[[</code> commands, ** for example, <code>[ -r ./file -a ! -l ./file ]</code> is deprecated in favor of <code>[ -r ./file ] && ! [ -l ./file ]</code>; * Use of the arithmetic syntax <code>$[...]</code> is deprecated in favor of <code>$((...))</code> or <code>((...))</code>, as appropriate; * Use of <code>^</code> as a pipeline is deprecated in favor of <code>|</code>; * Any uses of <code>expr</code> or <code>let</code>. === Shellshock === In September 2014, a [[security bug]] was discovered<ref>{{Cite news |last=Juliana |first=Cino |date=10 June 2017 |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 |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/ |archive-date=June 21, 2019 |access-date=21 June 2019 }}</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 name="TR-20140924">{{Cite web |last=Leyden |first=John |date=September 24, 2014 |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 |archive-url=https://web.archive.org/web/20141016214010/http://www.theregister.co.uk/2014/09/24/bash_shell_vuln |archive-date=October 16, 2014 |access-date=September 25, 2014 |website=[[The Register]] }}</ref><ref name="NYT-20140925-NP">{{Cite news |last=Perlroth |first=Nicole |date=September 25, 2014 |title=Security Experts Expect 'Shellshock' Software Bug in Bash to Be Significant |url=https://www.nytimes.com/2014/09/26/technology/security-experts-expect-shellshock-software-bug-to-be-significant.html |url-status=live |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 |archive-date=April 5, 2019 |access-date=September 25, 2014 |work=[[The New York Times]] }}</ref><ref name="ZDN-20140929">{{Cite web |last=Seltzer |first=Larry |date=29 September 2014 |title=Shellshock makes Heartbleed look insignificant |url=https://www.zdnet.com/article/shellshock-makes-heartbleed-look-insignificant/ |url-status=live |archive-url=https://web.archive.org/web/20160514191755/http://www.zdnet.com/article/hackers-jump-on-the-shellshock-bash-bandwagon/ |archive-date=May 14, 2016 |website=[[ZDNet]] }}</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 |last=Huzaifa Sidhpurwala |date=2014-09-24 |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 |archive-url=https://web.archive.org/web/20140925035842/https://securityblog.redhat.com/2014/09/24/bash-specially-crafted-environment-variables-code-injection-attack/ |archive-date=September 25, 2014 |access-date=September 25, 2014 |publisher=[[Red Hat]] }}</ref> The bug had been present in the [[source code]] since August 1989 (version 1.03)<ref name="Seclists-20141004">{{Cite web |last=Chazelas |first=Stephane |date=4 October 2014 |title=oss-sec mailing list archives |url=http://seclists.org/oss-sec/2014/q4/102 |url-status=live |archive-url=https://web.archive.org/web/20141006093452/http://seclists.org/oss-sec/2014/q4/102 |archive-date=October 6, 2014 |access-date=4 October 2014 |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. === 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 | title=bashbug man page | website=linux.die.net | date=2017-10-21 | url=https://linux.die.net/man/1/bashbug | archive-url=https://web.archive.org/web/20181002232146/https://linux.die.net/man/1/bashbug | archive-date=2018-10-02 | url-status=dead }}</ref><ref>{{cite web | title=bashbug(1) Mac OS X Manual Page | website=developer.apple.com | date=2014-06-04 | url=https://developer.apple.com/library/prerelease/mac/documentation/Darwin/Reference/ManPages/man1/bashbug.1.html | archive-url=https://web.archive.org/web/20141006131347/https://developer.apple.com/library/prerelease/mac/documentation/Darwin/Reference/ManPages/man1/bashbug.1.html | archive-date=2014-10-06 | url-status=dead}}</ref> == See also == {{Portal|Free and open-source software}} * [[Comparison of command shells]] * {{section link|Multics#Commands}}, exec_com: the first command processor.<ref name="Multics History, info segment on exec_com" /> === Unix Shells === * [[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;" available on Arch.<ref name="Arch Linux, Command-line shell">{{Cite web |title=Command-line shell - ArchWiki |url=https://wiki.archlinux.org/title/Command-line_shell |website=wiki.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 Wiki: Shell">{{Cite web |title=Shell - Debian Wiki |url=https://wiki.debian.org/Shell |website=wiki.debian.org}}</ref> * [[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)]] {{Clear}} == Further reading == * {{Cite web |last=Pouzin |first=Louis |date=2 April 1965 |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 |access-date=5 January 2024 |website=mit.edu |publisher=MIT }} * {{Cite book |last=Stephenson |first=Neal |title=[[In the Beginning... Was the Command Line]] |date=2003 |publisher=HarperCollins |isbn=978-0380815937 }} * {{Cite web |title=Evolution of shells in Linux |url=https://developer.ibm.com/tutorials/l-linux-shells/ |access-date=19 May 2024 |website=ibm.com }} * {{Cite web |title=Scripting Reference :: Scripting with the Bourne-Again Shell (Bash) |url=https://decal.ocf.berkeley.edu/labs/scripting/ |access-date=19 May 2024 |website=berkeley.edu }} * {{Cite web |title=IRIS :: Instructional & Research Information Systems :: FAQ: Unix :: About UNIX Shells |url=https://iris.eecs.berkeley.edu/faq/unix/ |access-date=19 May 2024 |website=berkeley.edu }} * {{Cite web |title=Learning the Bash Shell, 2e |url=https://www.oreilly.com/library/view/learning-the-bash/1565923472/ch01s03.html |access-date=14 January 2025 |quote=This book describes the latest release of bash 2.0 (version 2.01, dated June 1997). }} * {{Cite web |title=Apple Developer, Documentation Archive, Shell Style Guide |url=https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/Introduction/Introduction.html |access-date=20 January 2025 |quote=Copyright © 2003, 2014 Apple Inc. All Rights Reserved. ... Updated: 2014-03-10 }} * {{Cite web |title=Google, Shell Style Guide |url=https://google.github.io/styleguide/shellguide.html |access-date=20 January 2025 }} <!-- Syntax for Notes, ie, footnotes / endnotes. 2009: [[GNU General Public License|GPL-3.0-or-later]]{{efn|GPL-3.0-or-later since version 6.0 (2009-02-20).}}<br />1997: [[GNU General Public License|GPL-2.0-or-later]]{{efn|GPL-2.0-or-later from version 2.1 (1997-06-05) until version 5.2 (2006-10-11).}}<br />1994: [[GNU General Public License|GPL-1.0-or-later]]{{efn|GPL-1.0-or-later from ? until version 2.0 (1994-08-04).}} {{ notelist }} --> == References == {{Reflist}} {{GNU}} {{Unix shells}} {{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:Unix shells]]
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Authority control
(
edit
)
Template:CVE
(
edit
)
Template:Citation
(
edit
)
Template:Cite book
(
edit
)
Template:Cite mailing list
(
edit
)
Template:Cite news
(
edit
)
Template:Cite newsgroup
(
edit
)
Template:Cite web
(
edit
)
Template:Clear
(
edit
)
Template:Code
(
edit
)
Template:Div col end
(
edit
)
Template:Div col start
(
edit
)
Template:Dunno
(
edit
)
Template:GNU
(
edit
)
Template:How-to section
(
edit
)
Template:Infobox software
(
edit
)
Template:Key
(
edit
)
Template:Key press
(
edit
)
Template:Main
(
edit
)
Template:Man
(
edit
)
Template:Multiref
(
edit
)
Template:Multiref2
(
edit
)
Template:No
(
edit
)
Template:Portal
(
edit
)
Template:Programming languages
(
edit
)
Template:Prose
(
edit
)
Template:Redirect
(
edit
)
Template:Reflist
(
edit
)
Template:Section link
(
edit
)
Template:Short description
(
edit
)
Template:Split portions
(
edit
)
Template:Timeline-end
(
edit
)
Template:Timeline-item
(
edit
)
Template:Timeline-start
(
edit
)
Template:Unix shells
(
edit
)
Template:Use dmy dates
(
edit
)
Template:Yes
(
edit
)
Search
Search
Editing
Bash (Unix shell)
Add topic