Bash
This article needs additional citations for verification. Please help improve this article by adding reliable references. Unsourced material may be challenged and removed. (June 2007) |
File:Bash-org.png | |
---|---|
File:Bash demo.png Screenshot of bash and sh sessions demonstrating some features | |
Developer(s) | Chet Ramey |
Written in | C |
Operating system | Cross-platform |
Platform | GNU |
Available in | English, multilingual (gettext) |
Development status | Active |
Type | Unix shell |
License | GNU General Public License version 3+[1] |
Website | Home page |
Bash is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for Bourne-again shell.[2] 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,[3] and the phrase "born again." Bash was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer.[4]
Bash 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 MS-DOS by the DJGPP project and to Novell NetWare.
Features
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 (nested parentheses broke under Bash, for example, in the Mozilla startup script some years back [WHEN?]), 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'. Bash function declarations (using the key word 'function') are not compatible with Bourne/Korn/POSIX/C-shell scripts. 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.
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.[5]
Brace expansion
Brace expansion is a feature, originating in csh, that allows arbitrary strings to be generated using a similar technique to filename expansion. However the generated names 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
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 wilcards 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.
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 installed as a secondary shell and the script begins with #!/bin/bash interpreter directive (known as a "shebang line"). This problem became particularly important when Ubuntu began to ship the Debian Almquist shell (dash) as the default scripting shell in October 2006, causing a wide variety of scripts to fail.
Keyboard shortcuts
The following shortcuts work when using default (Emacs) key bindings. Vi-bindings can be enabled by running set -o vi
.
See also: Readline
- Template:Keypress : Autocompletes from the cursor position.
- Template:Keypress : moves the cursor at the beginning of the line (equivalent to the key Template:Keypress).
- Template:Keypress : (end) moves the cursor at the line end (equivalent to the key Template:Keypress).
- Template:Keypress : (previous) recalls the previous command (equivalent to the key Template:Keypress).
- Template:Keypress : (next) recalls the next command (equivalent to the key Template:Keypress).
- Template:Keypress : (research) recalls the last command including the specified character(s). A second Template:Keypress recalls the next anterior command which corresponds to the research
- Template:Keypress : 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).
- Template:Keypress : executes the found command from research.
- Template:Keypress : clears the screen content (equivalent to the command
clear
). - Template:Keypress : clears the line content before the cursor and copy it in the clipboard.
- Template:Keypress : clears the line content after the cursor and copy it in the clipboard.
- Template:Keypress : clears the word before the cursor and copy it in the clipboard.
- Template:Keypress : (yank) adds the clipboard content from the cursor position.
- Template:Keypress : sends an EOF marker, which (unless disabled by an option) closes the current shell (equivalent to the command
exit
). - Template:Keypress : sends the signal SIGINT to the current task, which aborts and closes it.
- Template:Keypress : sends the signal SIGTSTP to the current task, which suspends it. To return to it later one can enter
fg 'process name'
(foreground). - Template:Keypress Template:Keypress : (because x has a crossing shape) alternates the cursor with its old position.
- Template:Keypress Template:Keypress : (editor because it takes the $EDITOR shell variable) edits the current line in vi.
- Template:Keypress : (forward) moves forward the cursor of one word.
- Template:Keypress : (backward) moves backward the cursor of one word.
- Template:Keypress : cuts the word before the cursor.
- Template:Keypress : cuts the word after the cursor.
- Template:Keypress : capitalizes every character from the cursor's position to the end of the current word.
- Template:Keypress : lowers the case of every character from the cursor's position to the end of the current word.
- Template:Keypress : capitalizes the character under the cursor and moves to the end of the word.
- Template:Keypress : cancels the changes and put back the line as it was in the history.
See also
References
- ↑ GNU Project. "README file". http://tiswww.case.edu/php/chet/bash/README. "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)"
- ↑ C Programming by Al Stevens, Dr. Dobb's Journal, July 1, 2001
- ↑ Fresh Faces by Rosalyn Lum, Dr. Dobb's Journal, June 1, 2005
- ↑ Ramey, Chet (1994-08-01). "Bash - the GNU shell (Reflections and Lessons Learned)". Linux Journal. http://www.linuxjournal.com/article/2800#N0xa50890.0xb46380. Retrieved 2008-11-13.
- ↑ The syntax matches that shown on the
regex(7)
man page.
External links
Search Wikibooks | Wikibooks has a book on the topic of |
- Bash home page
- Template:Tldp
- Template:Tldp
- "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.
|
ar:باش bs:Bash bg:Bash ca:Bash cs:Bash de:Bourne-again shell es:Bash eo:Bash eu:Bash fr:Bourne-Again shell gl:Bash ko:본 어게인 셸 hr:Bash id:Bourne-Again shell is:Bash it:Bash he:Bourne-again shell hu:Bash ms:Bash nl:Bash ja:Bash pl:Bash pt:Bash ro:Bash ru:Bash sk:Bash sr:Баш sh:Bash fi:Bash sv:Bash th:Bash tr:Bash uk:Bash zh:Bash
If you like SEOmastering Site, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...
- Pages using deprecated source tags
- Pages with syntax highlighting errors
- Pages with broken file links
- Articles needing additional references from June 2007
- Articles with invalid date parameter in template
- All articles needing additional references
- Text-oriented programming languages
- Scripting languages
- Unix shells
- GNU project software
- Command shells
- Free software programmed in C
- Free cross-platform software