Rescuing orphaned refs ("GNUBSD" from rev 418154671) |
Reverted to revision 418154671 by Msnicki; This is an encyclopedic article, not a place to simply repeat whatever GNU publishes.. (TW) |
||
Line 24: | Line 24: | ||
}} |
}} |
||
'''Bash''' is a |
'''Bash''' is a [[Unix shell]] written by [[Brian Fox (computer programmer)|Brian Fox]] for the [[GNU Project]]. The name is an [[acronym]], a [[pun]] and descriptive. As an acronym, it stands for ''Bourne-again shell'', referring to its initial conception as a free [[open source]] [[clone (computing)|clone]] of the [[Bourne shell]] (sh).<ref name="GNUBSD"> |
||
⚫ | |||
It is distributed as [[Free Software]] under the [[GNU General Public License version 3|GNU General Public License v3]]<ref>Official Bash maintainer website | http://tiswww.case.edu/php/chet/bash/bashtop.html </ref>. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
</ref><ref> |
|||
{{Citation |
|||
| last = Hamilton |
|||
| first = Naomi |
|||
| author-link = http://www.computerworld.com.au/author/97635374/naomi-hamilton/articles |
|||
| title = The A-Z of Programming Languages: BASH/Bourne-Again Shell |
|||
| journal = Computerworld |
|||
| pages = 2 |
|||
| date = May 30, 2008 |
|||
| url = http://www.computerworld.com.au/article/222764/a-z_programming_languages_bash_bourne-again_shell/?pp=2&fp=16&fpid=1 |
|||
}} |
|||
</ref><ref>[http://www.ddj.com/cpp/184404693 C Programming] by Al Stevens, [[Dr. Dobb's Journal]], July 1, 2001</ref> |
|||
As a pun, it expressed that objective in a phrase that sounds the same as ''[[Born again (Christianity)|born again]]'', a term for spiritual rebirth.<ref> |
|||
{{Citation |
|||
| last = Gattol |
|||
| first = Markus |
|||
| title = Bourne-again Shell |
|||
| date = May 30, 2008 |
|||
| url = http://www.markus-gattol.name/ws/bash.html |
|||
| accessdate = Mar 8 2011 |
|||
}} |
|||
</ref> The name is also descriptive of what it did, ''bashing together'' the features of sh, [[C shell|csh]] and [[Korn shell|ksh]].<ref> |
|||
{{Cite newsgroup |
|||
| title = at&t-free ksh (was: job control is a bug, not a feature) |
|||
| author = Ian Darwin |
|||
| date = June 13, 1989 |
|||
| newsgroup = comp.os.minix |
|||
| id = |
|||
| url = http://groups.google.com/group/comp.os.minix/msg/63c036d82ceca4d6?hl=en |
|||
| accessdate = Nov 1 2010 |
|||
}} |
|||
</ref> |
|||
== History == |
== History == |
||
Line 38: | Line 78: | ||
| url = http://ftp.gnu.org/gnu/bash/bash-1.14.7.tar.gz |
| url = http://ftp.gnu.org/gnu/bash/bash-1.14.7.tar.gz |
||
}} |
}} |
||
</ref> after [[Richard Stallman]] became dissatisfied with the lack of progress being made by a prior developer.<ref name= |
</ref> after [[Richard Stallman]] became dissatisfied with the lack of progress being made by a prior developer.<ref name=GNUBSD/> Stallman and his [[Free Software Foundation]] (FSF) considered a free shell that could run existing sh scripts so strategic to a completely free system built from BSD and GNU code that this was one of the few projects they funded themselves, with Fox undertaking the work as an employee of FSF.<ref name=GNUBSD/><ref> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
</ref> Stallman and his [[Free Software Foundation]] (FSF) considered a free shell that could run existing sh scripts so strategic to a completely free system built from BSD and GNU code that this was one of the few projects they funded themselves, with Fox undertaking the work as an employee of FSF.<ref name=GNUBSD/><ref> |
|||
{{Cite web |
{{Cite web |
||
| author = [[Richard Stallman]] |
| author = [[Richard Stallman]] |
Revision as of 15:05, 12 March 2011
![]() Screenshot of Bash and sh sessions demonstrating some features | |
Original author(s) | Brian Fox |
---|---|
Initial release | June 7, 1989 |
Repository | |
Written in | C |
Operating system | Cross-platform |
Platform | GNU |
Available in | English, multilingual (gettext) |
Type | Unix shell |
License | GNU General Public License version 3+[1] |
Website | Bash GNU project home page |
Bash is a Unix shell written by Brian Fox for the GNU Project. The name is an acronym, a pun and descriptive. As an acronym, it stands for Bourne-again shell, referring to its initial conception as a free open source clone of the Bourne shell (sh).[2][3][4] As a pun, it expressed that objective in a phrase that sounds the same as born again, a term for spiritual rebirth.[5] The name is also descriptive of what it did, bashing together the features of sh, csh and ksh.[6]
History
Fox began coding Bash on January 10, 1988[7] after Richard Stallman became dissatisfied with the lack of progress being made by a prior developer.[2] Stallman and his Free Software Foundation (FSF) considered a free shell that could run existing sh scripts so strategic to a completely free system built from BSD and GNU code that this was one of the few projects they funded themselves, with Fox undertaking the work as an employee of FSF.[2][8] Fox released Bash as a beta, version .99, on June 7, 1989[9] and remained the primary maintainer until sometime between mid-1992[10] and mid-1994,[11] when he was laid off from FSF[12] and his responsibility was transitioned to another early contributor, Chet Ramey.[13][14][15]
Features
Bash is a POSIX shell with a number of extensions. It is the shell for the GNU operating system from the GNU Project. It can be run on most Unix-like operating systems. It is the default shell on most systems built on top of the Linux kernel as well as on Mac OS X and Darwin. It has also been ported to Microsoft Windows using Subsystem for UNIX-based Applications (SUA), or POSIX emulation provided by Cygwin and MSYS. It has been ported to DOS by the DJGPP project and to Novell NetWare.
The Bash command syntax is a superset of the Bourne shell command syntax. The vast majority of Bourne shell scripts can be executed by Bash without modification, with the exception of Bourne shell scripts stumbling into fringe syntax behavior interpreted differently in Bash or attempting to run a system command matching a newer Bash builtin, etc. Bash command syntax includes ideas drawn from the Korn shell (ksh) and the C shell (csh) such as command line editing, command history, the directory stack, the $RANDOM and $PPID variables, and POSIX command substitution syntax $(…). When used as an interactive command shell and pressing the tab key, Bash automatically uses command line completion to match partly typed program names, filenames and variable names.
Bash's syntax has many extensions which the Bourne shell lacks. Bash can perform integer calculations without spawning external processes, unlike the Bourne shell. Bash uses the ((…)) command and the $((…)) variable syntax for this purpose. Bash syntax simplifies I/O redirection in ways that are not possible in the traditional Bourne shell. For example, Bash can redirect standard output (stdout) and standard error (stderr) at the same time using the &> operator. This is simpler to type than the Bourne shell equivalent 'command > file 2>&1'. When using the 'function' keyword, Bash function declarations are not compatible with Bourne/Korn/POSIX scripts (the Korn shell has the same problem when using 'function'), but Bash accepts the same function declaration syntax as the Bourne and Korn shells, and is POSIX conformant. Due to these and other differences, Bash shell scripts are rarely runnable under the Bourne or Korn shell interpreters unless deliberately written with that compatibility in mind, which is becoming less common as Linux becomes more widespread. But in POSIX mode,[16] Bash conformance with POSIX is nearly perfect.
Bash supports here documents just as the Bourne shell always has. However, since version 2.05b Bash can redirect standard input (stdin) from a "here string" using the <<< operator.
Bash 3.0 supports in-process regular expression matching using a syntax reminiscent of Perl.[17]
Bash 4.0 supports associative arrays [16] allowing faked support for multi-dimensional arrays, in a similar way to awk:
declare -A a # declare an associative array 'a'
i=1; j=2 # initialize some indices
a[$i,$j]=5 # associate value "5" to key "$i,$j" (i.e. "1,2")
echo ${array[$i,$j]} # print the stored value at key "$i,$j"
Brace expansion
Brace expansion, also called alternation, is a feature copied from the C shell that generates the set of alternative combinations. The generated results need not exist as files. The results of each expanded string are not sorted and left to right order is preserved:
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
Brace expansions should not be used in portable shell scripts, because the Bourne shell will not produce the same output.
# A traditional shell does not produce the same output
echo a{p,c,d,b}e # a{p,c,d,b}e
When brace expansion is combined with wildcards, the braces are expanded first, then the resulting wildcards are substituted normally. Hence, a listing of JPEG and PNG images in the current directory could be obtained with:
ls *.{jpg,jpeg,png} # expands to *.jpg *.jpeg *.png - after which,
# the wildcards are processed
Startup scripts
When Bash starts, it executes the commands in a variety of different scripts.
When Bash is invoked as an interactive login shell, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.
When a login shell exits, Bash reads and executes commands from the file ~/.bash_logout, if it exists.
When an interactive shell that is not a login shell is started, Bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force Bash to read and execute commands from file instead of ~/.bashrc.
Some versions of Unix have especially contorted system scripts for Bash which will effectively violate the documented script load order by loading scripts too early or attempting to combine Bash startup with the startup scripts for other shells in various ways.[citation needed]
Portability
Shell scripts written with Bash-specific features (bashisms) will not function on a system using the Bourne shell or one of its replacements, unless Bash is also installed and the script begins with a "shebang line" of #!/bin/bash interpreter directive instead of #!/bin/sh.
Keyboard shortcuts
The following shortcuts work when using default (Emacs) key bindings. Vi-bindings can be enabled by running set -o vi
.
- Tab ↹ : Autocompletes from the cursor position.
- Ctrl+a : moves the cursor to the line start (equivalent to the key Home).
- Ctrl+e : (end) moves the cursor to the line end (equivalent to the key End).
- Ctrl+p : (previous) recalls the prior command (equivalent to the key ↑).
- Ctrl+n : (next) recalls the next command (equivalent to the key ↓).
- Ctrl+r : (research) recalls the last command including the specified character(s). A second Ctrl+r recalls the next anterior command which corresponds to the research
- Ctrl+s : Go back to the next more recent command of the research (beware to not execute it from a terminal because this command also launches its XOFF). If you changed that XOFF setting, use Ctrl+q to return.
- Ctrl+o : executes the found command from research.
- Ctrl+l : clears the screen content (equivalent to the command
clear
). - Ctrl+u : clears the line content before the cursor and copies it into the clipboard.
- Ctrl+k : clears the line content after the cursor and copies it into the clipboard.
- Ctrl+w : clears the word before the cursor and copies it into the clipboard.
- Ctrl+y : (yank) adds the clipboard content from the cursor position.
- Ctrl+d : sends an EOF marker, which (unless disabled by an option) closes the current shell (equivalent to the command
exit
). (Only if there is no text on the current line) - Ctrl+c : sends the signal SIGINT to the current task, which aborts and closes it.
- Ctrl+z : sends the signal SIGTSTP to the current task, which suspends it. To execute it in background one can enter
bg
. To bring it back from background or suspensionfg ['process name or job id']
(foreground) can be issued. - Ctrl+x Ctrl+x : (because x has a crossing shape) alternates the cursor with its old position.
- Ctrl+x Ctrl+e : edits the current line in the $EDITOR program, or vi if undefined.
- Alt+f : (forward) moves forward the cursor of one word.
- Alt+b : (backward) moves backward the cursor of one word.
- Alt+Del : cuts the word before the cursor.
- Alt+d : cuts the word after the cursor.
- Alt+u : capitalizes every character from the cursor's position to the end of the current word.
- Alt+l : lowers the case of every character from the cursor's position to the end of the current word.
- Alt+c : capitalizes the character under the cursor and moves to the end of the word.
- Alt+r : cancels the changes and put back the line as it was in the history.
See also
References
- ^ GNU Project. "README file".
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).
- ^ a b c
Chet Ramey (February 10, 1988). "GNU + BSD = ?". Newsgroup: comp.unix.questions. Retrieved Oct 30 2010.
{{cite newsgroup}}
: Check date values in:|accessdate=
(help) - ^
Hamilton, Naomi (May 30, 2008), "The A-Z of Programming Languages: BASH/Bourne-Again Shell", Computerworld: 2
{{citation}}
: Check|author-link=
value (help); External link in
(help)|author-link=
- ^ C Programming by Al Stevens, Dr. Dobb's Journal, July 1, 2001
- ^
Gattol, Markus (May 30, 2008), Bourne-again Shell, retrieved Mar 8 2011
{{citation}}
: Check date values in:|accessdate=
(help) - ^
Ian Darwin (June 13, 1989). "at&t-free ksh (was: job control is a bug, not a feature)". Newsgroup: comp.os.minix. Retrieved Nov 1 2010.
{{cite newsgroup}}
: Check date values in:|accessdate=
(help) - ^ Brian Fox (August 29, 1996), shell.c, Free Software Foundation
- ^
Richard Stallman (October 3, 2010). "About the GNU Project". Free Software Foundation. Retrieved Nov 1 2010.
{{cite web}}
: Check date values in:|accessdate=
(help) - ^
Brian Fox (forwarded by Leonard H. Tower Jr.) (June 8, 1989). "Bash is in beta release!". Newsgroup: gnu.announce. Retrieved Oct 28 2010.
{{cite newsgroup}}
: Check date values in:|accessdate=
(help) - ^
len (g...@prep.ai.mit.edu) (April 20, 1993). "January 1993 GNU's Bulletin". Newsgroup: gnu.announce. gnusenet930421bulletin@prep.ai.mit.edu. Retrieved Oct 28 2010.
{{cite newsgroup}}
: Check date values in:|accessdate=
(help) - ^ Ramey, Chet (1994-08-01). "Bash - the GNU shell (Reflections and Lessons Learned)". Linux Journal. Retrieved 2008-11-13.
- ^
Chet Ramey (October 31, 2010), Dates in your Computerworld interview, retrieved Oct 31 2010
{{citation}}
: Check date values in:|accessdate=
(help) - ^
Chet Ramey (June 12, 1989). "Bash 0.99 fixes & improvements". Newsgroup: gnu.bash.bug. Retrieved Nov 1 2010.
{{cite newsgroup}}
: Check date values in:|accessdate=
(help) - ^
Chet Ramey (July 24, 1989). "Some bash-1.02 fixes". Newsgroup: gnu.bash.bug. Retrieved Oct 30 2010.
{{cite newsgroup}}
: Check date values in:|accessdate=
(help) - ^
Brian Fox (March 2, 1990). "Availability of bash 1.05". Newsgroup: gnu.bash.bug. Retrieved Oct 30 2010.
{{cite newsgroup}}
: Check date values in:|accessdate=
(help) - ^ a b
"6.11 Bash POSIX Mode", The GNU Bash Reference Manual, for Bash, Version 4.1, December 23, 2009, retrieved Oct 26 2010
{{citation}}
: Check date values in:|accessdate=
(help); External link in
(help); Unknown parameter|chapterurl=
|chapterurl=
ignored (|chapter-url=
suggested) (help) - ^ The syntax matches that shown on the
regex(7)
man page.
External links
- Official website
- Bash reference manual
- Template:Tldp
- Template:Tldp
- Linux Shell Scripting Tutorial (LSST) v2.0 wiki
- "The Comprehensive List of bash Reference Documentation and Examples"
- Useful Bash History Tips and Tricks
- 2008 interview with GNU Bash's maintainer, Chet Ramey
- Working with BASH environment variables
- Video Tutorial for Creating a Bash Script
- Bash commands and examples
- Colorized Bash prompt - how to set up a colorized Bash prompt based on the current connection method (SSH, telnet, etc.).
- jBash Project is a Java Parser for the Bourne Again Shell
- The 'official' channel FAQ for freenode's #bash channel is BashFAQ.
- BASHDB - Bash with a built-in debugger.