User:Owittnan/Bash (Unix shell)

From Simple English Wikipedia, the free encyclopedia
An example session in the bash shell.
An example session in the bash shell.

Bash is a Unix shell and scripting language first released in 1989[1]. It was made by Brian Fox[2] for the GNU project. It is a free alternative to the Bourne shell. The name Bash is an acronym for Bourne Again Shell, a pun on the Bourne shell and being born again[3].

It follows the POSIX standard, with many extensions. It has features such as editing prompt styles, vim and GNU Emacs keybinding modes, program control with the fg, bg and jobs commands and command completion.

It is the default shell on many Linux distributions and was the default shell on macOS before the release of macOS Catalina in 2019, when the shell was switched to zsh.[4]. It has a lot of features from other shells. Its basic features are from the Bourne shell, but it also includes features from the csh/ksh such as the history command that shows what commands you have run.

Features[change | change source]

Bash has many features not present in the Bourne shell.

Brace expansion[change | change source]

The brace expansion feature is from csh. It creates alternative combinations. For example:

$ 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

This can also be used to generate intervals between a top and bottom value. For example:

$ cat file{1..4}.txt

will show the contents of file1.txt, file2.txt, file3.txt and file4.txt.

Configuration[change | change source]

Bash is configured through a hidden file (known as a dot file because files are hidden by placing a dot (.) before the file name) called .bashrc. This file is located in the user's home directory. In it, you can configure things like the prompt style, different keybinding modes (emacs and vi), custom commands called functions, and other names for commands called aliases. Below is an example .bashrc file.

set +o vi # set the vi keybinds
PS1="\u@\h: \w \$ " # set the prompt. this value will produce the same prompt as in the above picture (user@host: ~ $ ) without colours
alias e=vim # create the alias e. running e at the prompt will launch the vim editor
md() { # create a function. running md at the prompt will run any code within the { and }
    if [[ ! -d $1 ]]; then # check if the first argument doesn't exist as a directory
         mkdir $1 # if it doesn't, make it
         cd $1 # then change to it
    else # if it does exist
       echo Cannot create directory which already exists # print an error
    fi # end if loop
}

All of these options and more are documented in the bash reference manual.

References[change | change source]

  1. Brian Fox (forwarded by Leonard H. Tower Jr.) (June 8, 1989). "Bash is in beta release!". Newsgroupgnu.announce. Archived from the original on May 4, 2013. Retrieved October 28, 2010.
  2. Richard Stallman (forwarded with comments by Chet Ramey) (February 10, 1988). "GNU + BSD = ?". Newsgroupcomp.unix.questions. Usenet: 2362@mandrill.CWRU.Edu. Archived from the original on November 7, 2012. Retrieved March 22, 2011. 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.
  3. Richard Stallman (November 12, 2010). "About the GNU Project". Free Software Foundation. Archived from the original on April 24, 2011. Retrieved March 13, 2011. "Bourne Again Shell" is a play on the name Bourne Shell, which was the usual shell on Unix.
  4. Hughes, Matthew (2019-06-04). "Why does macOS Catalina use Zsh instead of Bash? Licensing". The Next Web. Archived from the original on December 31, 2020. Retrieved 2021-01-12.