Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Bash (Unix shell)
(section)
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!
===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 |publisher=[[GNU Project]] }}</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 |publisher=[[GNU Project]] }}</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 |publisher=[[GNU Project]] }}</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 |publisher=[[GNU Project]] }}</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=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=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 |publisher=[[GNU Project]] }}</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 === -->
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)