Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Bash (Unix shell)

From Wikipedia, the free encyclopedia
GNU replacement for the Bourne shell
This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages)
This articlecontainsinstructions or advice. Wikipedia is not a guidebook; please helprewrite such content to be encyclopedic or move it toWikiversity,Wikibooks, orWikivoyage.(August 2025)
icon
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Bash" Unix shell – news ·newspapers ·books ·scholar ·JSTOR
(August 2025) (Learn how and when to remove this message)
This articlecontainstoo many or overly lengthy quotations. Please helpsummarise the quotations. Consider transferring direct quotations toWikiquote or excerpts toWikisource.(August 2025) (Learn how and when to remove this message)
(Learn how and when to remove this message)

Bash
Original authorBrian Fox
DeveloperChet Ramey
Initial release8 June 1989; 36 years ago (1989-06-08)
Stable release
5.3[1] Edit this on Wikidata / 3 July 2025; 7 months ago (3 July 2025)
Written inC
Operating system
PlatformGNU
Available inMultilingual (gettext)
TypeShell (computing),Unix shell,command language
License
Websitewww.gnu.org/software/bash/
Repository

Bash (short for "Bourne Again SHell") is an interactivecommand interpreter andscripting language developed forUnix-likeoperating systems. Created in 1989 by Brian Fox for theGNU Project,[7] it is designed as a completelyfree software alternative for theBourne shell,sh, and other proprietaryUnix shells,[8] supported by theFree Software Foundation.[7] Having gained widespread adoption, Bash is commonly used as the defaultlogin shell for numerousLinux distributions.[9] It also supports the execution of commands from files, known asshell scripts, facilitatingautomation.

The Bash commandsyntax is asuperset of theBourne shell's syntax, from which all basic features of the Bash syntax were copied. As a result, Bash can execute the vast majority of Bourne shell scripts without modification. Some other ideas were borrowed from theC shell, its successortcsh, and theKorn Shell. It is available on nearly all modern operating systems, making it a versatile tool in various computing environments.

Definitions

[edit]

ASCII, strings and numbers

[edit]

The input language to the shell shall be first recognized at the character level.

— "POSIX 1003.1-2024, 2.10.1 Shell Grammar Lexical Conventions".The Open Group Base Specifications Issue 8, IEEE Std 1003.1-2024.The Open Group. Retrieved25 August 2025.

$printf'<newline>:  <%b>\n'$'\n'<newline>:  <>$printf'<tab>:      <%b>\n'$'\t'<tab>:      <>$printf'<space>:    <%s>\n'" "<space>:    < >$printf'<NUL>:      <%b>\n'$'\0'<NUL>:      <>

Any series of characters is called a "string", or sometimes a "string literal". In Unix-like operating systems, all characters, printable and non-printing, except for a few such as thenull character and forward slash/, can be used infilenames. In addition, all strings are case-sensitive.[10]

Bash, like many other programming languages, useszero-based numbering.

Control+key combinations

[edit]

The Control+key functionality is provided byGNU Readline and is available in interactive mode only.Certain keypress combinations allow a user to operate Bash to use tab completion and to search the command history.

  • Tab ↹ – Activate tab completion
  • – Scroll up (i.e. backward) in the command history
  • – Scroll down (i.e. forward) in the command history
  • Ctrl+r – Search the command history

Some keypress combinations also allow a user to operate the terminal emulator in order to move the cursor within the terminal window and to control the emulator program. By default, these keypress combinations in Bash mirror those ofEmacs.[11]

Default keybindings for control codes include:

  • Ctrl+f – Move the cursor one character to the right
  • Ctrl+b – Move the cursor one character to the left
  • Alt+f – Move the cursor one word to the right
  • Alt+b – Move the cursor one word to the left
  • Ctrl+a – Move the cursor to the beginning of the current commandline
  • Ctrl+c – Cancels the current command and presents a new prompt
  • Ctrl+d – Closes the current Bash instance, possibly also closing the terminal-emulator
  • Ctrl+e – Move the cursor to the end of the current commandline
  • Ctrl+q – Wake the terminal; buffered keypresses are then processed
  • Ctrl+s – Put the terminal to sleep
  • Ctrl+w – Remove one word to the left of the cursor
  • Ctrl+z – Stop a foregrounded process

Vi keybindings are also available and can be enabled by runningset-ovi.[12][13]

Syntax

[edit]

When Bash reads afull command line, the complete string is broken down intotokens."Tokens" are identified using, and separated from each other usingmetacharacters.

As of Bash 5.3, the 10 metacharacters are the space, tab, and newline, as well as the following characters:|&;()<>

"Blanks" are composed entirely of unquoted metacharacters,"operators" each contain at least one unquoted metacharacter and"words" may not include any unquoted metacharacters.

In practice, Bash breaks downfull command strings into tokens or groups of tokens thatdo contain metacharacters and tokens or groups of tokens that donot contain any metacharacters—called"words".From there it further breakswords down into more specific, meaningful pieces like command names, variable assignment statements, etc.

The two blanks are space and tab.

Operators

[edit]

Control operators perform acontrol function. They can be either a newline or one of the following:||,&&,&,;,;;,;&,;;&,|,|&,(, or).

Redirection operators redirect the input or output streams. They include<,>,&>,<<, and<<<.

Words

[edit]

Aword is a sequence of (non-meta-) characters treated as a single unit by the shell. Areserved word is a kind of aword that has a special meaning to the shell.[14]Aname is a kind of a word separate fromreserved words. Names consist solely of letters, underscores and numbers; which begins with either a letter or an underscore; which, however, may not begin with a number.Names also calledidentifiers, may be used for naming variables and functions.

Sixteen of the twenty-two"reserved words", which may be characters or words are as follows:

'!''[[''{'']]''}'caseinesacfordodoneifthenelifelsefi...

Names may only contain the charactersABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.

In the following example of a full command string,metacharacters have a comma placed above them,,,reserved words have a caret placed beneath them,^, and othertokens have a backtick placed also beneath them,`.

$#,  ,    ,   ,,    ,       ,,  ,$ifechofoo;thenbar=abc;fi$# ^^ ```` ```  ^^^^ ```````  ^^

Subshells

[edit]

A "subshell" is an additional instance of the shell which has been initialized by a current instance of the shell.When a "parent" shell creates a subshell, or a "child" shell, an exact copy of the parent's environment information is re-created and becomes the environment of the subshell.

In Bash, in non-arithmetic contexts, one can force the use of a subshell by enclosing a full command string insingle parentheses.

$echofoofoo$(echofoo)foo$

For this simple case, the preceding two commands are equivalent, however, use of subshells can have certain unexpected side effects.There are numerous different forms of syntax which can cause the initialization of a subshell.[clarification needed]

Expansion

[edit]
Main article:String interpolation

Data structures

[edit]

Bash offers variables and arrays as data structures, and though there are numerous kinds of each of these available, the data structures are relatively simple compared to other languages likeC orJava.[15] All data is stored in memory as a string.

Beginning a word with a dollar character signifies that the word is the name of a variable or array. Surrounding the dollar / variable name syntax in double quotes is always advised. This practice shields the value(s) held by the parameter(s) from unwanted side effects.[clarification needed]

Wrapping the variable name in curly brackets (braces){} is recommended for readability and consistency between variables and arrays. When writing variables, curly brackets are optional and square brackets would be a syntax error. The parameter names are always on the left side of the equals sign and values are always on the right.

Variables

[edit]

A variable is assigned to using the syntaxname=value.

To use a variable, the syntax$name is used, or${name}, which expands to the value assigned to the variable.

The latter syntax must be used for certain names to prevent unwanted side effects. For example,$10 will be parsed as${1}0, so using${10} means it will be parsed as intended.

Positional parameters, usually passed to a bash script, are denoted by the variables numbered starting from $0.Special parameters are signified by punctuation characters.[15] For example,$@ expands to a list of the first through last positional parameters, "individually requoted, separated by spaces".[attribution needed]

Environment variables are signified by all capital letters. Environment variables include UNIX variables likeLESS_SIGUSR1, and Bourne shell variables such asHOME.[15] Scripting variables are signified by all lower case letters or CamelCase. This is only convention; any variable can be passed to theexport command to be made into an environment variable.

Arrays

[edit]

Arrays are data structures which hold multiple values.[16] Arrays have a set of square brackets placed at the end of the variable name and inside the curly braces. When writing arrays, curly braces and square brackets are required.

An array is assigned using the syntaxname=( one or more elements ). It is expanded using${quux[@]} or${quux[*]} or${quux[1]}, depending on the use case.

Each kind of parameter is distinguished by a specificnaming convention.[15]

Since Bash 4.0,[17] Bash also supportsassociative arrays.

In this article, examples of variables from this section include${foo}, PID, PWD, EUID, $$,${quux} and${zork}.

Execution

[edit]
Main article:Execution (computing)

"Execution" of a given program occurs when a user (or some other program) asks the operating system to act upon the instructions contained in the given program.

By default, Bash reads user code one line at a time, interprets any newline or semi-colon character; as the end of the current command, and executes commands in sequence. If an interactive command extends beyond the width of the terminal emulator, it is usually possible to keep typing and the command will wrap around. To extend a command beyond a newline onto an additional line, it is necessary that the final character of the first line be an unescaped backslash,\, which signals "line continuation".Bash always finishes parsing and executing one full commandline before moving on to and beginning with the parsing of the next commandline.

$foo=aabar=bbquux=cczork=dd;set-oxtrace$:"${foo}";:"${bar}"+ : aa+ : bb$:"${quux}"\>:"${zork}"+ : cc : dd$

The first word of a command line is known as the "command position".Under UNIX coventionality, the first word of the command line is always some kind of command, and the rest of the words in the command line string are either options for the command, arguments for the options, or some kind of input upon which the command will operate. "Options" are also called "flags", "switches", or, more formally, "operators". When Bash attempts to locate a command for execution, the directories it searches are those listed in the$PATH variable and the current working directory.[18]

$# [COMMAND POSITION] [OPTION] [ARGUMENTS]$# ,--^   ,------------^   ,----^$declare-pUSERBASH_VERSIONdeclare -x USER="liveuser"declare -- BASH_VERSION="5.2.37(1)-release"$

Users and PS1

[edit]

A user account can be created for either a human or a programmatic user.In Unix-like operating systems, there are two kinds of users: "privileged" and "regular". A privileged user, such as root or the operating system kernel, is allowed to do anything whatsoever on the machine. Unprivileged users are limited in various ways.

When an interactive shell session waits for user input, by default it prints a particular string of characters to the screen. In Bash, thevalue of this waiting-string is held in the shellvariable$PS1. For regular users, a common default value for$PS1 is the dollar character,$.[a] For thesuperuser, a common default value is hashtag (#)

$sudo--login--userroot[sudo] password for liveuser:#vim/home/liveuser/names.txt#exit$grep-ebob./names.txtgrep: ./names.txt: Permission denied

Modes

[edit]

Programming paradigm

[edit]

Although most users think of the shell as an interactive command interpreter, it is really a programming language in which each statement runs a command. Because it must satisfy both the interactive and programming aspects of command execution, it is a strange language, shaped as much by history as by design.

— Brian W. Kernighan &Rob Pike,Kernighan, Brian W.;Pike, Rob (1984).The UNIX Programming Environment. Englewood Cliffs:Prentice-Hall.ISBN 0-13-937699-2.

Bash is written in C. A modular style can be approximated through good style and careful design.[19] It is often used in animperative orprocedural style.

Interactive and non-interactive modes

[edit]

As acommand processor, Bash can operate in two modes: interactive or non-interactive.Ininteractive mode, commands are usually read from aterminal emulator. In non-interactive mode, which facilitatesautomation, commands are usually read from named files known today asshell scripts. When executed as a standalone command at thecommand-line interface (CLI), by default Bash opens a new shell in interactive mode.

Scripts

[edit]

Shell scripts are text files that containcode, oftencommands, intended to be read and acted upon by some particularinterpreter in abatch process in anon-interactive mode and without any further user interaction. Interpreted scripts areprograms that do not require theirsource code to becompiled: all of the relevant source code is contained within the script.There are many programs which can serve as a script interpreter:Perl,AWK, etc. Interpreted scripts are most often written for Unix shells.

The first two characters of the first line of any (executable) shell script begins with a something called ashebang: literally the characters hashtag (#) and bang (!) side by side.

$cat./example.sh#!/bin/envbashecho fooexit$

If a script is intended to be run by a user as a stand-alone program on the commandline, then it is referred to as an"executable". By convention, the filenames ofexecutable unix shell scripts are identified the suffix.sh. The "execute" bit can be enabled on a shell script with the utilitychmod:

$ls-l./example.sh-rw-r--r--.1 liveuser liveuser 32 Aug  3 22:33 example.sh$./example.shbash: ./example.sh: Permission denied$chmod0744./example.sh$ls-l./example.sh-rwxr--r--.1 liveuser liveuser 32 Aug  3 22:33 example.sh$./example.shfoo$

Thesource builtin

[edit]

With thesource, or synonymous. command, Bash reads and executes shell commands from any text file by name.[20]

Login and non-login shells

[edit]
Main article:Session (computer science)

Bash can be executed as alogin shell, or "session leader," in both interactive and non-interactive modes via the--login option. "Logging in" requires userauthentication. For this reason, only one login shell exists per user session. In GNU/Linux, a user's login shell is identified in the /etc/passwd file.

$awk-F':''$1 ~ /root/'/etc/passwdroot:x:0:0:Super User:/root:/bin/bash

When a human user initiates a login session, this procedure often occurs in agraphical user interface (GUI).When a user opens aterminal emulator, the emulator executes anon-login instance of the user's login shell.

Logging out of a shell session from within a terminal emulator can be accomplished with the exit command or, by default in Bash, pressing Ctrl+d.

Startupsource files

[edit]
Main articles:Unix shell andHidden file and hidden directory

When Bash starts, it usessource to execute commands in a variety ofdotfiles (see lists below).[21]These dotfiles, unlike shell scripts, typically have neither the execute permission enabled nor ahash-bang. By default Bash will source a somewhat different set of files, and in a different sequence, depending on:[22]

  • How Bash is called: interactively, non-interactively, invoked with namesh
  • Which options are used:--login,--rcfile,--norc,--posix
  • Which environment variables are defined:BASH_ENV,ENV, and
  • Which files exist:
    • /etc/profile
    • ~/.bash_profile
    • ~/.bash_login
    • ~/.profile
    • ~/.bash_logout, and
    • ~/.bashrc among others.

Of course, any startup file can also execute commands from any other file. Startup files can affect shell behavior, terminal emulators, theX window system and thewindow manager.

POSIX mode

[edit]
Main articles:POSIX andPOSIX terminal interface

ThePOSIX IEEE 1003.1 standard specifies a common set of definitions that any shellsystem application (bash,dash,zsh, etc.) may conform to.Any shelluser script (./myscript.sh) written in conformance with POSIX guidelines should be executable by any shellsystem application that hasimplemented the POSIX specification. As a result, there can be a reasonable expectation that POSIX-compliant scripts can be executed with success on any Unix or Unix-like operating systems which implements the POSIX standard (Linux,OpenBSD,Oracle Linux,HP-UX, etc.). These scripts are considered "portable" as they are and without any further modifications. The portion of POSIX that applies to shells and command line utilities is a subset of a larger group ofPOSIX standards that further specify how terminals and terminal emulators aught to function in order to also be considered portable.

When Bash is operating in POSIX mode, fewer features are available but the resulting code can be executed on a greater variety of operating systems.

To enable POSIX mode at the initialization of an interactive shell, Bash can be executed as eithersh,bash --posix orbash -o posix.[23] To cause a script to be initialized in POSIX mode, one would use the either the hashbang#! /bin/env sh or the less portable#!/bin/sh. When an instance of Bash is operating in POSIX mode, the environment variable$POSIXLY_CORRECT is defined, and the value of the environment variableSHELLOPTS includes the stringposix.

$declare-pPOSIXLY_CORRECTbash: declare: POSIXLY_CORRECT: not found$sh$declare-pPOSIXLY_CORRECTdeclare -- POSIXLY_CORRECT="y"$

The full list of features available in Bash which are not specified by POSIX is considerable.[24] Here is a partial list:

  • Any arrays other than the array of positional parameters,$@, are not POSIX
  • The double bracket extended test construct,[[...]], is not POSIX
    • [...] andtest are POSIX
  • One of the double-parentheses arithmetic-evaluation syntaxes,((...)), is not POSIX
    • $((...)) is POSIX
  • Brace expansion,kernel{,-headers}, is not POSIX
  • Dynamic scoping of parameters and thelocal builtin are not POSIX
  • Process substitution,<(...), is not POSIX
  • Certain string-manipulation operations in parameter expansions are not POSIX
  • Most Bash builtin commands are not POSIX
    • The commandenable-s prints the list of Bourne special builtins, which are POSIX
      $enable-s|wc--lines16$enable|wc--lines61
    • Theenable builtin itself is not POSIX
    • In Bash, in non-POSIX mode, the. andsource builtins are synonymous
      • The. (i.e., 'dot') builtinis POSIX, however
      • Thesource builtinis not POSIX
  • The$EPOCHSECONDS and$EPOCHREALTIME shell variables are not POSIX

System commands which are available in modern Unix-like operating systems, and which are also specified by POSIX, may have fewer option flags or fewer relevant environment variables available under POSIX. Most (such asls) are standalone programs in the/bin,/usr/bin,/sbin or/usr/sbin directories (in Linux, typically provided byGNU coreutils orBusyBox) rather than Bash builtins.

Because of these and other differences, modern (version 5) Bash shell scripts are rarely runnable "as-is" under the Bourne or legacy Korn shell interpreters. Scripting with portability in mind is becoming less common as GNU/Linux becomes more widespread.[23][25]

Code that is valid syntax in Bash but not specified by POSIX is called a "bashism". The programcheckbashisms can be used to make sure that a script can be executed inDebian Linux without any portability errors.[26] Vidar Holen'sshellcheck is another staticlinter written inHaskell which can parse script syntax for compatibility with any or all of bash, dash, ksh, and Bourne sh.[27]

The syntax requirements for each shell are each a little different. For example, Debian's policy allows some extensions in their scripts (as they are in thedash shell),[25] while a script intending to support pre-POSIX Bourne shells, likeautoconf'sconfigure, are even more limited in the features they can use.[28]

Other modes

[edit]

Restricted mode

[edit]

A restricted shell is used to set up an environment more controlled than the standard shell. A restricted shell behaves identically to bash with the exception that numerous actions are disallowed or not performed, including:

  • Changing directories with thecd builtin.
  • Setting or unsetting the values of theSHELL,PATH,HISTFILE,ENV, orBASH_ENV variables.
  • Specifying command names containing slashes on the CLI.
  • Using absolute pathnames as arguments to the.,history, orhash-p commands.
  • Specifying a path search with. -p orcommand-p.
  • Importing function definitions and parsing the value ofSHELLOPTS from the shell environment at startup.
  • Redirecting output using the>,>,<>,>&,&>, and>> redirection operators.
  • Using theexec builtin to replace the shell with another command.
  • Altering shell builtins.

Once restricted mode is enabled, it cannot be disabled. These restrictions are enforced after any startup files are read, and it does not apply to shell scripts. Restricted mode is rarely used.

Privileged mode

[edit]

In Bash, "privileged mode" is a rarely used option inherited[citation needed] from the SVR4.2UNIX System V shell (circa 1992).[29] It can be enabled withset-p and disabled withset+p.[30] When privileged mode is enabled, theSHELLOPTS shell variables includes the string "privileged".

Extended debugging mode

[edit]

Enabled viabash --debugger at invocation or viashopt-sextdebug during either interactive or non-interactive modes. It uses a separate program calledbashdb.[31]extdebug is not available in POSIX mode. See documentation for more information. See also§ Debugging.

Compatibility modes

[edit]

Bash-4.0 introduced the concept of a shell compatibility level, specified as a set of options to the shopt builtin (compat31, compat32, compat40, compat41, and so on). There is only one current compatibility level – each option is mutually exclusive. The compatibility level is intended to allow users to select behavior from previous versions that is incompatible with newer versions while they migrate scripts to use current features and behavior. It's intended to be a temporary solution.[32]

— Bash Reference Manual, 6.12 Shell Compatibility Mode

Observability

[edit]

The xtrace option

[edit]

When xtrace is enabled, simple debugging content is printed to the terminal.It can be enabled withset -o xtrace orset -x, and disabled withset +o xtrace,set +x orset -.These options are also accepted at the commandline and at hash-bangs:#!/bin/bash -x, etc.

$bash-x$echo$((2+2))+ echo 44$set--123$printf'<%s>\n'"$@"+ printf '<%s>\n' 1 2 3<1><2><3>$

The xtrace shell setting is specified by POSIX.See also§ Debugging.

The verbose option

[edit]

The verbose option prints strings to the terminal as they are read, and before any expansions are performed. Rarely used.[33]

Comments

[edit]

Comments can be a valuable way of clarifying information or explaining a script or source file to someone else who might not be familiar with the scripter's intentions or context.

Standard comments in Bash are denoted with a hash character:#.Any text to the right of the hash to the end of the line will be ignored.Inline comments are allowed, but hash comments will not print during debugging. See also:§ xtrace.

Comments denoted with a colon character,:, originated with theThompson shell. Any arguments to the right of colon: builtin are ignored. Inline comments are not possible, but colon comments will print during debugging and any parameters will have been expanded.[34]

$# Define foo$foo=bar# An inline hash comment occurs on the same line as a command$set-x$# A regular comment (no output)$:"${foo}"+ : bar$

Exit codes

[edit]

When bash executes commands,exit status codes, also called "return codes," are produced which can offer some insight into the manner in which a program ceased running.The value of the most recently captured exit code is held within the shell parameter, 'question mark:'$?.In non-arithmetic contexts, (i.e., most of the time) the numerical or "Boolean" value of "true" is zero (0), and the value of "false" is one (1).

When a system command has executed, the intended meaning of its exit status can most often be found in its man page; usually a zero indicates success and a nonzero exit status indicates some kind of failure condition or partial success.ping is a well known command with three meaningful exit codes: 0, 1, and 2.

In Bash, within arithmetic contexts, the numerical truth values are reversed: "true" is one and "false" is zero.An arithmetic context can usually be identified by the syntax((...)) or$((...)).If an arithmetic statement evaluates to the integer zero, then the statement is considered "true," and the exit code is one.If the statement evaluates to any number other than zero the arithmetic statement is "false" and the exit code is zero.

Not all Linux/UNIX commands provide meaningful exit codes beyond zero and one, and there is no standard system for definitions of exit codes in Linux.

$true;echo"$?"# Exit code means "true"0$false;echo"$?";echo# Exit code means "false"1$$bash-c'exit 99';printf'exit-code: %d\n\n'"$?"exit-code: 99$$((1-1));printf'%d\n'"$?"# This exit code means "true"1$((1+1));printf'%d\n'"$?"# ...and this exit code means "false"0

Job control

[edit]
Main article:Job control (Unix)

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:

$command1;command2$command3$

In this example, when command1 is finished, command2 is executed, and when command2 has completed, command3 will execute.Abackground 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.

$command1&$

Or to have a concurrent execution of command1 and command2, they must be executed in the Bash shell in the following way:

$command1&command2$

In this case command1 is executed in the background,& symbol, returning immediate control to the shell that executes command2 in the foreground.A process can be stopped and control returned to bash by typingCtrl+z while the process is running in the foreground.[35]A list of all processes, both in the background and stopped, can be achieved by runningjobs:

$jobs[1]-  Running                  command1 &$

In the output, the number in brackets refers to the job id.The plus sign signifies the default process forbg andfg.The text "Running" and "Stopped" refer to theprocess state.The last string is the command that started the process.

The state of a process can be changed using various commands.Thefg command brings a process to the foreground, whilebg sets a stopped process running in the background.bg andfg 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 ofjobs.Thekill command can be used to end a process prematurely, by sending it asignal.The job id must be specified after a percent sign:

$sleep100&[1] 4904$kill%1$jobs[1]+  Terminated                    sleep 100$

Job control, also known as "Monitor mode," is enabled by default in interactive shells, and can be disabled withset+m.

Signals

[edit]

Signaling is a means ofinter-process communication (IPC). Sometimes a commandline process may seem to freeze in the middle of execution.In these instances it may become necessary to identify which process may be blocked and to manually end the offending process.

At an interactive terminal, it is usually sufficient to press Ctrl-c to end the current foreground process and return control back to the user prompt, or to press Ctrl-z to suspend it.Occasionally attempting to suspend a process will succeed when attempts to cancel a process appear unresponsive.In other cases it may be necessary to use the kill program to send an IPC signal.In this example, we use the kill command from a second terminal screen to terminate the process with PID 4331.

$tty# Terminal one/dev/pts/0$whoamiliveuser$sleep1000# Command hangs
$tty# Terminal two/dev/pts/1$whoamiliveuser$psaux|grep-esleep-ePIDUSER         PID %CPU %MEM    VSZ   RSS TTY      STAT START    TIME COMMANDliveuser    4331  0.0  0.0 230336  2312 pts/1    S+   11:19    0:00 sleep 1000liveuser    4333  0.0  0.0 231248  2516 pts/0    S+   11:19    0:00 grep --color=auto -e sleep -e PID$kill4331$psaux|grep-esleep-ePID# The sleep process has endedUSER         PID %CPU %MEM    VSZ   RSS TTY      STAT START    TIME COMMANDliveuser    4333  0.0  0.0 231248  2516 pts/0    S+   11:19    0:00 grep --color=auto -e sleep -e PID$
$tty# Terminal one again/dev/pts/0$whoamiliveuser$sleep1000Terminated$

In Unix-like operating systems, a user is allowed to instruct the kernel to send a signal to a process that is owned by the user.A regular user may not send a signal to a privileged process.Signals can be sent to a process using the kill builtin or using the system binary of the same name.

$whoamiliveuser$psaux|awk'$2 ~ /\<1\>/'# Let\s view some info on the kernel process, process 1.root           1  0.0  0.2  37140 20440 ?        Ss   04:44    0:18 /usr/lib/systemd/systemd --switched-root --system --deserialize=53 rhgb$kill-sSIGKILL1bash: kill: (1) - Operation not permitted$type-akillkill is a shell builtinkill is /usr/bin/kill$/usr/bin/kill-sSIGKILL1kill: sending signal to 1 failed: Operation not permitted$

The most commonly used signals can be viewed withkill -L | head -n 4.Each IPC signal is associated with a signal number, but exit codes and signal codes are two different things. While sending a process an IPC signal of 9 (a "KILL" signal) will almost certainly terminate the process immediately, it will most likely not result in the process returning an exit code of 9.

By default in Bash, builtin kill sends a TERM ("terminate") signal.It's common for commandline utilities to respond to a SIGTERM by shutting down and exiting cleanly. (TERM and SIGTERM are the same, the SIG- prefix to all signal names can be omitted.)The Ctrl-c keypress sequence in Bash sends a SIGINT, interrupt signal, to the foreground process.The Ctrl-z keypress sequence sends the SIGSTOP, stop signal.[36]When a process receives a SIGKILL, the process terminates immediately and messily.It is recommended to use SIGKILL only as a last resort.[37]The SIGKILL signal cannot be blocked or handled.

Processes can "catch" and "handle" IPC signals they receive.A user can use the kill builtin to "send" an IPC signal to another process.That target process can set up a mechanism, some plan beforehand, for how to repsond whenever any particular signal might be received, or "caught."The way a target program responds is referred to as how the program "handles" receiving the signal.In the man pages one can see how some system commands will print out certain information to the terminal when they receive a SIGHUP: for example, thedd command.[38]

When bash is interactive, in the absence of any traps, it ignoresSIGTERM (so thatkill0 does not kill an interactive shell), and catches and handlesSIGINT (so that the wait builtin is interruptible). When bash receivesSIGINT, it breaks out of any executing loops. In all cases, bash ignoresSIGQUIT. If job control is in effect, bash ignoresSIGTTIN,SIGTTOU, andSIGTSTP.[39]

—  bash(1)

By default Bash shell scripts receive and respond to any and all IPC signals sent to them, however, Bash scripts can utilize the trap builtin to catch and handle signals.[40]

$cat./trap-example.sh#!/usr/bin/envbashtrap umask EXITecho barexit 0$chmod0700trap-example.sh$./trap-example.shbar0077$

There are a few signals which are only available from within Bash as GNU extensions:ERR,EXIT,RETURN andDEBUG.These signals can be useful in debugging, and can only be sent and handled by shell builtins.See also§ Debugging.

Values of parameters

[edit]

There are many different implementations ofecho. Some have the-e option, and some don't.[41]The list of options is not uniform across implementations, thoughecho andprintf are both specified by POSIX.If a scripter wishes to know the precise value of a string contained by a variable, then the most consistent way of doing so is to useprintf.

For any string containing any character (besides null?) including digits, the format specifier is%s.[citation needed]

$foo=abcbar=123$printf'<%s>\n'"${foo}""${bar}"<abc><123>$

For digits only, the format specifier is%d.

$printf'<%d>\n'"${foo}""${bar}"bash: printf: abc: invalid number<0><123>$

Withprintf, a newline is never included in the output unless the scripter includes a newline in the format string.In the example below, where a newline has been omitted from the format string, the value of PS1 is printed on the same line as the output of the previous command.

$printf'<%s>'"${foo}""${bar}"<abc><123>$

Another very consistent method is to usedeclare-p.The output ofdeclare-p can be reused as input.However, not all variables and parameters can be printed usingdeclare-p, for example, the values of the Special Parameters.The Special Parameter hashtag,"$#", reports how many Positional Parameters are currently defined.

$declare-pfoobardeclare -- foo="abc"declare -- bar="123"$declare-p"$#"bash: declare: 0: not found$

For a full string of input at an interactive shell...

$declare-p#

...the hashtag would be interpreted by Bash as an inline comment.With the comment and all text to the right of it removed, the command that Bash would execute would bedeclare-p.This command would, according tohelp declare, "display the values and attributes of each NAME," i.e., each variable, and, "if no NAMEs are given, display the values and attributes and values of all variables," which can be over 100 lines of output.

On the other hand,printf cannot display variables' attributes.See also§ Debugging.

$readonlyfoo$declare-pfoodeclare -r foo="abc"$printf'<%s>'"${foo}"<abc>$

Environment

[edit]
This articlecontainsinstructions or advice. Wikipedia is not a guidebook; please helprewrite such content to be encyclopedic or move it toWikiversity,Wikibooks, orWikivoyage.(January 2019)

Configurable execution environment(s):[42]

  • Shell andsession startup files such as~/.bashrc and~/.profile (i.e.,dotfiles);
  • Settings (setbuilt-in) and shell options (shoptbuilt-in) which alter shell behavior;

Shell and session startup Files (a.k.a., "dot files")

When Bash starts, it executes the commands in a variety ofdot files.[21]Unlike Bash shell scripts, dot files typically have neither the execute permission enabled nor aninterpreter directive like#!/bin/bash.

  • Legacy-compatible Bash startup example

The example~/.bash_profile below is compatible with the Bourne shell and gives semantics similar to csh for the~/.bashrc and~/.bash_login.The[ -rfilename ] && cmd is ashort-circuit evaluation that tests iffilename exists and is readable, skipping the part after the&& if it is not.

[-r~/.profile]&&~/.profile# set up environment, once, Bourne-sh syntax onlyif[-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 onlyfi# End of "if" block
  • Operating system issues in Bash startup

Some versions ofUnix andLinux contain Bash system startup scripts, generally under the/etc 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 theX 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 thewindow manager.These issues can often be addressed using a~/.xsession or~/.xprofile file to read the~/.profile — which provides the environment variables that Bash shell windows spawned from the window manager need, such asxterm orGnome Terminal.

Standard streams

[edit]

Standard streams - STDIN, STDOUT and STDERR

Commands

[edit]

System commands

[edit]

Aliases

[edit]

Aliases allow a string to be substituted for a word that is in a position in the input where it can be the first word of a simple command. Aliases have names and corresponding values that are set and unset using the alias and unalias builtin commands.

— GNU Bash Reference Manual, Ch 6.6 Aliases[43][44][45][46][47]

Keywords and reversed words

[edit]
  • function
    • Bash function declarations which include this particular keyword are not compatible with Bourne/Korn/POSIX scripts, however, Bash does accepts the function declaration syntax used by Bourne, Korn and POSIX-compliant shells.

Functions

[edit]

Shell functions are a way to group commands for later execution using a single name for the group. They are executed just like a "regular" simple command. When the name of a shell function is used as a simple command name, the shell executes the list of commands associated with that function name. Shell functions are executed in the current shell context; there is no new process created to interpret them.

—  GNU Bash Reference Manual, Ch 3.3 Shell Functions[48][49][50][51][52][53]

Builtin commands

[edit]
  • Various Built-In Commands:
    • POSIX Special builtins:[54]
      • cd,pwd, etc.
    • set[55]
      • Xtrace: [set-x |set-oxtrace ]. The shell's primary means of debugging. Both xtrace and verbose can be turned off at the same time with the commandset-.
      • Verbose: [set-v |set-overbose ]. 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 aset-v 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.[56]
      • Both xtrace and verbose can be turned off at the same time with the commandset-.
    • shopt[57]
      • expand-aliases: On by default in interactive shells. Some developers discourage its use in scripts.

PATH and system commands

[edit]

When the shell looks for external commands, it relies on the Bourne shell variable$PATH.$PATH contains a list of directories separated by colons,:.Beginning with the leftmost directory and selecting directories in a left to right pattern, each directory is searched until a match is found.In Linux, so that a user can locate additional commands, it's common practice for distribution administrators and package developers to alter the value of an end user's$PATH by including source files in/etc/profile.d and other locations.

When looking for the command,chmod, for instance, after considering internal commands and finding nothing, Bash will search the directories in$PATH and will select the absolute path of the first executable found that has a basename which matches the search string.[18]

If there is more than one commandecho available in the directories listed in$PATH, during the process of parsing and executing a commandline, by default only the first command found will be selected.$PATH lookups are slow.The shell speeds up the commandline execution process by remembering command locations in a hash table.To perform a full$PATH search without any interference from the hash table, remove the current table withhash-r and search for all kinds of commands withtype-a.

$# Force a full path search$PATH=${PATH}:${HOME}$printf'echo script_file: "$@"\n'>./echo$chmod0700./echo$hash-r;type-aechoecho is a shell builtinecho is /usr/bin/echoecho is /home/liveuser/echo$

In order to execute a commandline with a command found later in the$PATH string, you can specify an absolute path or you can anchor path resolution relative to the current working directory.

$/home/liveuser/echofooscript_file: foo$./echobarscript_file: bar$

For security reasons it is advisable to make sure the directories in PATH are not world-writeable, or are writeable only by root and trusted users.

Command lookup

[edit]
  • Command position: after expansions, the first word of the full text of the command line.
  • Command name lookup is performed, in the following order:
  • The resulting string is executed as a command.

Control structures

[edit]
See also:Control structures forCondition testing andshort-circuit evaluation

Subshells

[edit]

Subshells:(...);

Pipelines

[edit]

However, by using a pipeline, they can engage in multiple cycles of computation at the same time, substantially increasing their speed. In a pipelined control unit, different instructions simultaneously go through the process but at different points. While one instruction is being fetched, a second is being decoded, and so forth.Unix-stylepipelines:|.

Logical operators

[edit]
  • AND (&&)
  • OR (||)
  • NOT (!)

Bash supplies "conditional execution" command separators that make execution of a command contingent on theexit code set by a precedent command.For example:

$cd"$SOMEWHERE"&&./do_something||echo"An error occurred">&2

Where./do_something is only executed if thecd (change directory) command was "successful" (returned an exit status of zero) and theecho command would only be executed if either thecd or the./do_something command return an "error" (non-zero exit status).

Iteration

[edit]
Main article:Iteration § Computing

ITERATION: Sometimes programs are repeated indefinitely or until a specific outcome is reached. Each execution of the instructions is an "iteration."[58]

  • while,until, andselect loop compound commands;
  • Arithmetic C-style and list-enumeratingfor loop compound commands; and
  • continue,break,return, andexit flow control commands;

Compound commands

[edit]

compound: something formed by a union of elements or parts.[59]

— Merriam-Webster's Collegiate Dictionary

Bash also supportsif...fi andcase...esac forms of conditional command evaluation.[c]

Testing

[edit]

Built in commands for testing file attributes, comparing string and integer values, etc.:

  • Traditionaltest command,
  • Traditional single bracket test:[,
  • Modern double bracket test:[[...]], which includes advanced features:
  • ((...)) numeric evaluation and testing; this includes almost all "C" language operators for arithmetic and numeric comparison;

For all commands the exit status is stored in the special variable$?.

Regular Expressions

[edit]

Bash 3.0 supports in-processregular expression matching using a syntax reminiscent ofPerl.[61]Regexp matching is limited to strings on the right side of the=~ operator in the[[..]] extended test construct.[62]

[[$line=~[[:space:]]*(a)?b]] means values for line like 'aab', ' aaaaaab', 'xaby', and ' ab' will all match, as will a line containing a 'b' anywhere in its value.

Coprocesses

[edit]

A coprocess is a shell command preceded by the coproc reserved word. A coprocess is executed asynchronously in a subshell, as if the command had been terminated with the '&' control operator, with a two-way pipe established between the executing shell and the coprocess.[63]

— Bash Reference Manual, 3.2.6 Coprocesses

Data manipulation

[edit]

Word Splitting

[edit]

Split into words (i.e.,word splitting)

Quoting

[edit]

When in doubt -- Quote![64]

— Mastering Linux Shell Scripting, by Andrew Mallett

Bash has certainquoting rules: uses of

  • single quotes'...'
  • double quotes"..."
  • backslashes\, and
  • ANSI-C quoting$'...'.

See also§ Locales,$"..."

See also backticks`...`:§ Deprecated syntax.

Unicode

[edit]

Support forUnicode inecho-e and ANSI-C quoting.

Brace Expansion

[edit]
$echokernel{,-headers}kernel kernel-headers

Brace expansion, also called alternation, is a feature copied from theC shell.It generates a set of alternative combinations.[65]Generated results need not exist as files.The results of each expanded string are not sorted and left to right order is preserved:

$echoa{p,c,d,b}eape ace ade abe$echo{a,b,c}{d,e,f}ad ae af bd be bf cd ce cf

Users should not use brace expansions in portable shell scripts, because theBourne shell does not produce the same output.

$# 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

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:

ls*.{jpg,jpeg,png}# expands to *.jpg *.jpeg *.png – after which,# the wildcards are processedecho*.{png,jp{e,}g}# echo just shows the expansions –# and braces in braces are possible.

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.

$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$echofile{1..4}.txtfile1.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

When brace expansion is combined with variable expansion (a.k.a.,parameter expansion andparameter substitution) the variable expansion is performedafter the brace expansion, which in some cases may necessitate the use of theeval built-in, thus:

$start=1;end=10$echo{$start..$end}# fails to expand due to the evaluation order{1..10}$evalecho{$start..$end}# variable expansion occurs then resulting string is evaluated1 2 3 4 5 6 7 8 9 10

Tilde Expansion

[edit]
[icon]
This section is empty. You can help byadding to it.(August 2025)

Parameter and variable expansion

[edit]
  • Type
  • Shell parameters
  • Environment variables
  • User variables
  • Scope
  • Arrays
  • Parameter Expansion
    Expansion syntaxes which can perform some tasks more quickly than external utilities, including, among others:
    • Pattern Substitution
      • ${foo//x/y} forsed 's/x/y/g',
    • Remove Matching Prefix or Suffix Pattern
      • ${bar##[a-zA-Z0-9]*} forcut -c8-,
    • Enumerate Array Keys
      • ${!array[@]}, and
    • Display Error if Null or Unset
      • ${var:?error message},

Pathname expansion

[edit]

Pathname expansion, i.e., shell-styleglobbing andpattern matching using*,?,[...].[f]

Locales

[edit]

Locale-specific translation via$"..." quoting syntax.[69]

Process redirections and parsing

[edit]

Command substitution

[edit]

Command substitution:$(...),

Process substitution

[edit]

Process substitution,<() or>(), when a system supports it:

Bash supportsprocess substitution using the<(command) and>(command) 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 temporarynamed pipes where necessary).

Arithmetic expansion

[edit]

Arithmetic expansion,((...)) or$((...)), including

Bash can perform integer calculations ("arithmetic evaluation") without spawning external processes.It uses the((...)) command and the$((...)) variable syntax for this purpose.

Redirection

[edit]

Redirections of Standard Input, Standard Output and Standard Errordata streams are performed, including

  • File writing,>, and appending,>>,
  • Here documents,<<,
  • Here strings,<<<, which allow parameters to be used as input, and
  • A redirection operator,>|, which can force overwriting of a file when a shell'snoclobber setting is enabled;

Its syntax simplifiesI/O redirection.For example, it can redirectstandard output (stdout) andstandard error (stderr) at the same time using the&> operator.This is simpler to type than the Bourne shell equivalent 'command>file2>&1'.Bash supportshere documents.Since version 2.05b Bash can redirectstandard input (stdin) from a "here string" using the<<< operator.

Command parsing

[edit]
  • (A) Comments are ignored, from an unquoted# (hash) to the end of the same line;[70][71]
  • (B) Commands are parsed one line at a time:
    • Control structures are honored, and
    • Backslash\ escapes are also honored at the ends of lines;
  • (C) Split into words (i.e.,word splitting) according toquoting rules,
    • Including ANSI-C quoting$'...';
  • (D) Seventypes of expansions are performed in the following order on the resulting string:
    1. (Type 1) Brace expansionkernel{-headers},
    2. (Type 2) Tilde expansion~,
    3. In a left-to-right fashion:
    4. Word splitting (again),
    5. (Type 7) Pathname expansion, i.e., shell-styleglobbing andpattern matching using*,?,[...],[f]
    6. Quote removal;
  • (E)Redirections of Standard Input, Standard Output and Standard Errordata streams are performed, including
    • File writing,>, and appending,>>,
    • Here documents,<<,
    • Here strings,<<<, which allow parameters to be used as input, and
    • A redirection operator,>|, which can force overwriting of a file when a shell'snoclobber setting is enabled;
  • (F) Command name lookup is performed, in the following order:
    1. Commands internal to theshell:
    2. Commands external to the shell:
  • (G) The resulting string is executed as a command.

Interactive-only features

[edit]

Command History

[edit]

Unlimited sizecommand history.[72]This feature is available in interactive mode only.

Directory stack

[edit]

A directory stack (pushd andpopd built-ins) feature is available in interactive mode only.

Programmable completion

[edit]

Also known as "tab completion" or "command-line completion", when a user presses theTab, within an interactive command-shell Bash automatically uses any available completion scripts to suggest partly typed program names, filenames and variable names.[73][4] 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 supports programmablecompletion via built-incomplete,compopt, andcompgen commands.[74]The feature has been available since the beta version of 2.04 released in 2000.[75]These commands enable complex and intelligent completion specification for commands (i.e., installed programs), functions, variables, and filenames.[76]

Thecomplete andcompopt two commands specify how arguments of some available commands or options are going to be listed in thereadline input.As of version 5.1 completion of the command or the option is usually activated by the Tab keystroke after typing its name.[76]This feature is available in interactive mode only.

Prompts

[edit]

Configurableprompts.This feature is available in interactive mode only.

Documentation

[edit]

User Manual

[edit]

Auser manual for Bash is provided by the GNU Project.It is sometimes considered to be a more user-friendly document than the man page."You may also find information about Bash ...by looking at/usr/share/doc/bash,/usr/local/share/doc/bash, or similar directories on your system."[77]On GNU/Linux systems, if theinfo program is available then the GNU Manual version relevant for your installation should also be available atinfo bash.[78][79]

Man page

[edit]

The most recent technical manual, or'man page', is intended to be the authoritative explanatory technical document for the understanding of how bash operates.On GNU/Linux systems, the version relevant for your installation is usually available through theman program atmanbash.[78][39][80]

help builtin

[edit]

With recent versions of Bash, information on shell built-in commands can be found by executinghelp,help[nameofbuiltin] orman builtins at a terminal prompt where bash is installed.

Theprintf command can be invoked viaenv to ensure that you run the program found via your shell's search path, and not a shell alias or built-in function:envprintf--help.[81]

POSIX Specification

[edit]

For the purpose of allowing inter-operability among different shell programs running on different operating systems, thePOSIX Specification influences how modern UNIX-like shells are written.Bash "is intended to be a conformant implementation of the IEEE POSIX"Shell and Utilities" portion of the IEEE POSIX specification (IEEE Standard 1003.1)."[82]The most recent publication of the standard (2024) is available online.[83]

As the standard upon which bash is based, the POSIX Standard, or IEEE Std 1003.1,[84]et seq, is especially informative.

Further resources

[edit]

"The project maintainer also has a Bash page which includes Frequently Asked Questions",[77][85][86]this FAQ is current as of bash version 5.1 and is no longer updated.

Informal avenues of support are available via IRC at libera.chat, in the #bash channel, and mailing lists are available atBash - GNU Project - Free Software Foundation.

Security and vulnerabilities

[edit]

Root scripts

[edit]

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,rm-rf${dir}/, but the variable$dir is left undefined.In Linux, if the script was executed by a regular user, the shell would attempt to execute the commandrm -rf / 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 usesudo on a per-command basis instead.

CGI scripts

[edit]

CGI scripts are a significant source of vulnerability.[87][88][89][clarification needed]

builtineval

[edit]

"The eval command is extremely powerful and extremely easy to abuse."[90]

Input validation

[edit]

"Input validation is the process of ensuring data has undergone data cleansing to confirm it has data quality, that is, that it is both correct and useful."

Input validation is performed to ensure only properly formed data is entering the workflow in an information system, preventing malformed data from persisting in the database and triggering malfunction of various downstream components. Input validation should happen as early as possible in the data flow, preferably as soon as the data is received from the external party.[91]

— OWASP Input Validation Cheat Sheet

Shellshock

[edit]

In September 2014, asecurity bug was discovered[92]in the program.It was dubbed "Shellshock." Public disclosure quickly led to a range ofattacks across theInternet.[93][94][95]

Exploitation of the vulnerability could enablearbitrary code execution inCGI scripts executable by certain versions of Bash.The bug involved how Bash passed function definitions to subshells throughenvironment variables.[96]The bug had been present in thesource code since August 1989 (version 1.03)[97] 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 theCommon Vulnerability identifiers CVE-2014-6271, CVE-2014-6277 and CVE-2014-7169, among others.Under CVSS Metrics 2.x and 3.x, the bug is regarded as "high" and "critical", respectively.

Deprecated syntax

[edit]
icon
This sectiondoes notcite anysources. Please helpimprove this section byadding citations to reliable sources. Unsourced material may be challenged andremoved.(August 2025) (Learn how and when to remove this message)
  • Backtick style command substitutions:`...` is deprecated[98] in favor of
    • $(...);
  • Use of-a or-o intest/[/[[ commands,
    • for example,[-r./file-a!-l./file] is deprecated in favor of
      • [-r./file]&&![-l./file];
  • Use of the arithmetic syntax$[...] is deprecated in favor of
    • $((...)) or
    • ((...)), as appropriate;
  • Use of^ as a pipeline is deprecated in favor of|;
  • Any uses ofexpr orlet.

Debugging

[edit]

Table of Features

[edit]
Bash features which can be useful during debugging.[4][57][99]
FeaturePOSIX 2024DescriptionBash ver.
Grammar typeFormal nameSyntax
Special Built-In Utilityset / xtraceset-xYesThe shell'sprimary means of debugging.

It "writes to standard error a trace for each command after it expands the command and before it executes it."

?
Special ParametersExit Status"$?"Yes"Expands to the shortest representation of the decimal exit status."?
Parameter ExpansionsIndicate Null or Unset"${parameter:?[word]}"Yes"Where the expansion of[word], perhaps an error message or a line number, is written to standard error and the shell exits with a non-zero exit code."?
Special ParametersPID of Invoked Shell"$$"Yes"Expands to the shortest representation of the decimal process ID of the invoked shell."?
Special Built-In Utilityset / verboseset-vYes"Writes its input to standard error as it is read."?
Special Built-In Utilityset / pipefailset-opipefailYes"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."?
Special Built-In Utilityset / nounsetset-uYesWhen 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.

?
Special Built-In Utilityset / errexitset-eYesErrexit 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 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.

?
Special Built-In Utilitytrap / EXITtrap'[arg]'EXITYes"If a signal specifier is0 orEXIT,[arg] is executed when the shell exits." If[arg] contains expansions, then[arg] should be in single quotes.?
Utilityprintfprintf'<%s>\n'"${var}"YesA means of reliably printing the contents of a variable.?
Bash VariablesBASHPID"${BASHPID}"No"Expands to the process ID of the current bash process."[100]?
Bash VariablesBASH_ARGC"${BASH_ARGC[@]}"No"An array variable whose values are the number of parameters in each frame of the current bash execution call stack."[101]?
Bash VariablesBASH_ARGV"${BASH_ARGV[@]}"No"An array variable containing all of the parameters in the current bash execution call stack."[102]?
Bash VariablesBASH_LINENO"${BASH_LINENO[@]}"No"An array variable whose members are the line numbers in source files where each corresponding member of"${FUNCNAME[@]}" was invoked."[103]?
Bash VariablesBASH_REMATCH"${BASH_REMATCH[@]}"No"An array variable whose members are assigned by the=~ binary operator to the[[ conditional command."[104]?
Bash VariablesBASH_SOURCE"${BASH_SOURCE[@]}"No"An array variable whose members are the source filenames where the corresponding shell function names in the"${FUNCNAME[@]}" array variable are defined."[105]?
Bash VariablesBASH_XTRACEFD"${BASH_XTRACEFD}"No"If set to an integer corresponding to a valid file descriptor, Bash will write the trace output generated whenset-x is enabled to that file descriptor."[106]?
Bash VariablesEPOCHREALTIME"${EPOCHREALTIME}"No"Each time this parameter is referenced, it expands to the number of seconds since the Unix Epoch (seetime(3)) as a floating point value with micro-second granularity."[107]?
Bash VariablesFUNCNAME"${FUNCNAME[@]}"No"An array variable containing the names of all shell functions currently in the execution call stack."[108]?
Bash VariablesLINENO"${LINENO}"No"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."[109]?
Bash VariablesPIPESTATUS"${PIPESTATUS[@]}"No"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)."[110]?
Bash VariablesPPID"${PPID}"No"The process ID of the shell's parent."[111]?
Bash VariablesPS4"${PS4}"No"The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace."[112]?
Shell Builtinset / restrictedset-rNoRestricted 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.

?
Shell Builtinshopt / extdebugshopt-sextdebugNo"Behavior intended for use by debuggers."?
Shell Builtintrap / DEBUGtrap'[arg]'DEBUGNo"If a sigspec is DEBUG, the command arg is executed before" certain kinds of commands.?
Shell Builtintrap / ERRtrap'[arg]'ERRNo"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.?
Shell Builtintrap / RETURNtrap'[arg]'RETURNNo"If a sigspec is RETURN, the command arg is executed each time a shell function or a script executed with the. orsource builtins finishes executing."?
  • Shell features specified byPOSIX:
    • Parameter Expansions:[113]
    • Special Parameters:[114][115]
    • Special Built-In Utilityset:[116][117]
    • Special Built-In Utilitytrap:[117][118]
      • POSIX does specify certain uses of thetrap builtin: ...
    • Utilityprintf: a means of reliably printing the contents of a variable:
  • Bash features not specified by POSIX:
    • Bash Variables:[119][120]
    • Shell Builtinset:[116][117]
    • Shell Builtinshopt:[121][117]
    • Shell Builtintrap:[118][117]
      • While POSIX does specify certain uses of thetrap builtin, the following signal specs are Bash extensions: ...
  • Third party debugging utilities:
    • ShellCheck: Shell script analysis tool;[122][27]
    • devscripts-checkbashisms: Check whether a /bin/sh script contains any common bash-specific constructs;[123][26]
    • kcov: Code coverage tool without special compilation options;[124]
    • Bashdb: The Bash symbolic debugger.[31][125]

Examples

[edit]

With the"${var:?}" parameter expansion, an unset or null variable can halt a script.

$catex.sh#!/bin/bashbar="foo is not defined"echo "${foo:?$bar}"echo this message doesn't print$./ex.sh./ex.sh: line 3: foo: foo is not defined$

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 POSIX doesn't have named array, only the list of arguments,"$@", which can be re-set by theset builtin.

$# In POSIX shell:$set--"a"" b"">  c "$printf',%s,\n'"$@",a,, b,, c,

Note that in Bash, the number of spaces before the newline is made clear.

$# In Bash:$array=("a"" b"">  c " )$declare-parraydeclare -a array=([0]="a" [1]=" b" [2]=$' \n c ')

Printing an error message when there's a problem.

$caterror.sh#!/bin/envbashif ! lsblk | grep sdbthen  echo Error, line "${LINENO}"fi$./error.shError, line 130

Usingxtrace.If errexit had been enabled, thenechoquux would not have been executed.

$cattest.sh#!/bin/envbashset -xfoo=bar; echo "${foo}"falseecho quux$./test.sh+ foo=bar+ echo barbar+ false+ echo quuxquux

Note:$BASHPID differs from$$ in certain circumstances, such as subshells that do not require bash to be reinitialized.

$echo$(echo$BASHPID$$)$$$BASHPID              25680    16920 16920 16920#||||#|||\--$BASHPIDoutsideofthesubshell#||\--$$outsideofthesubshell#|\--$$insideofthesubshell#\--$BASHPIDinsideofthesubshell

Bug reporting

[edit]
"bashbug" redirects here. For The widely reported September 2014 bug found in Bash, seeShellshock (software bug).

An external command calledbashbug 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).[126][127]

History

[edit]

Shell script functionality originated with files called "runcoms" in reference to the 1963macro processor of the same name.The suffix "rc" is short for "runcom."[128]The term"shell" was coined by Louis Pouzin in 1964 or 1965,and appeared in his 1965 paper, "The SHELL, A Global Tool for Calling and Chaining Procedures in the System," which describes many features later found in many UNIX shells.[129][130]TheASCII standard forcharacter encoding was defined in 1969 in a document calledRequest for Comments (RFC) 20.[131]

Timeline

[edit]

Significant events in Bash history are listed below:

DateEvent
1988-01-10

Brian Fox begancoding Bash afterRichard Stallman became dissatisfied with the lack of progress being made by a prior developer.[132]Stallman and theFSF 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.[132][133]

1989-06-08

Fox released Bash as a beta, version 0.99.[134]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."[135]Eventually it supported "regular expressions (similar to Perl), and associative arrays".

1991

Bash holds historical significance as one of the earliest programs ported to Linux byLinus Torvalds, alongside the GNU Compiler (GCC).[136]

1992 ~ 1994

Brian Fox retired as the primary maintainer sometime between mid-1992[137]and mid-1994.[138][139]His responsibility was transitioned to another early contributor, Chet Ramey.[85][140][7][9]Since then, Bash has become the most popular default interactive shell among the major GNU/Linux distributions, such asFedora,Debian, andopenSUSE, as well as among their derivatives and competitors.[141][142]

1994-01-26

Debian – initial release.Bash is the default interactive and non-interactive shell.[143]

1996-12-31

Chet Ramey released bash 2.0.The license was GPL-2.0-or-later

1997-06-05

Bash 2.01 released.

1998-04-18

Bash 2.02 released.

1999-02-19

Bash 2.03 released.

2000-03-21

Bash 2.04 released.

2000-09-14

Bug-bash mailing list exists.[144]

2001-04-09

Bash 2.05 released.[145]

2003

Bash became the default shell on Apple's operating systems (i.e., MacOS) starting with OS X 10.3 Panther.[146][147]It was available on OS X 10.2 Jaguar as well where the default shell was tcsh.

2004-07-27

Bash 3.0 released.[148]

2005-12-09

Bash 3.1 released.[149]

2006-10-12

Bash 3.2 released.[150]The license was GPL-2.0-or-later.

2006

Ubuntu replace bash with dash as its default shell.

2009-02-20

Bash 4.0 released[151]Its license is GPL-3.0-or-later.

2010-01-02

Bash 4.1 released.[152]

2011-02-14

Bash 4.2 released.[153]

2012

OnSolaris 11, "the default user shell is the Bourne-again (bash) shell."[154]

2014-02-27

Bash 4.3 released.[155]

2014-09-08

Shellshock (software bug).[156][157]Patches to fix the bugs were made available soon after the bugs were identified.[158]

2015

Termux and other terminal emulation applications provide availability of Bash onAndroid.

2016-09-15

Bash 4.4 released.

2009 ~ 2018

Apple declines to accept version 4 of Bash being licensed under version 3 of theGNU GPL, and ceases to supply upgrades to Bash beyond version 3.2 (as supplied inMacOS Mojave).

2019-06-05

Apple declareszsh its default shell[159]and supplies version 5.7 in itsCatalina release of MacOS.[160][161][162]

2019-01-07

Bash 5.0 released.[163]

2020-12-07

Bash 5.1 released.[164]

2022-09-26

Bash 5.2 released.

2025

Bash 5.3 released.

See also

[edit]

Unix shells

[edit]

Graphical interface to scripts

[edit]

There are many programs that allow you to create a graphical interface for shell scripts.

  • curses - curses is a terminal control library for Unix-like systems, enabling the construction oftext user interfaces (TUI) applications.
  • dialog - is a utility that allows you to create dialog boxes in the console, using thecurses andncurses libraries.
  • gtkdialog - is the most functional utility for creating graphical applications on bash scripts.[167]
  • kdialog - is a KDE equivalent of zenity.[168]
  • ncurses - a programming library for creatingtextual user interfaces (TUI's) that work across a wide variety of terminals.
  • whiptail - is an analogue of the dialog utility, it uses thenewt library.[169]
  • xdialog - is a replacement fordialog that is designed to give programs launched from the terminal anX Window System interface.
  • yad - is a fork of zenity, with more features.[170]
  • zenity - is the most popular application for creating a graphical interface for scripts.[168][171]

Further reading

[edit]
  • [A]
    • "Shell Scripting Primer".apple.com. Apple. Retrieved8 August 2025.Copyright © 2003, 2014 Apple Inc All Rights Reserved. ... Updated: 2014-03-10

Notes

[edit]
  1. ^not to be confused with the shell variable$$
  2. ^abShell scripts do not require compilation before execution and, when certain requirements are met, can be invoked as commands by using their filename.
  3. ^concept drawn fromALGOL 68;[60]
  4. ^Bash 4 also switches its license toGPL-3.0-or-later.
  5. ^In February 2009,[66]Bash 4.0[d][67]introduced support forassociative arrays.[4] Associative array indices are strings, in a manner similar toAWK orTcl.[68] They can be used to emulate multidimensional arrays.
  6. ^ab Although they can be used in conjunction, the use of brackets in pattern matching,[...], and the use of brackets in the testing commands,[ and[[ ... ]], are each one different things.
  7. ^for this functionality, see current versions ofbc andawk, among others.

References

[edit]
  1. ^Chet Ramey (5 July 2025)."Bash-5.3-release available". Retrieved5 July 2025.
  2. ^"GNU Bash".Free Software Foundation, Inc.GNU Project.Archived from the original on 26 April 2019. Retrieved8 August 2025.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).
  3. ^"bash-1.11".oldlinux.org. Archived fromthe original on 15 October 2021. Retrieved8 August 2025.See test.c for GPL-2.0-or-later
  4. ^abcd"BashFAQ/061: Is there a list of which features were added to specific releases (versions) of Bash?".wooledge.org.Archived from the original on 2 March 2021. Retrieved8 August 2025.
  5. ^"bash-1.05".oldlinux.org. Archived fromthe original on 6 May 2021. Retrieved8 August 2025.
  6. ^"Is there a way to download the presumably initial bash source bash-0.99?".unix.stackexchange.com. Retrieved8 August 2025.
  7. ^abc
  8. ^"Bash - GNU Project - Free Software Foundation".www.gnu.org.
  9. ^abMorris, Richard (14 December 2015)."Chet Ramey: Geek of the Week".Simple Talk.Archived from the original on 31 July 2020. Retrieved8 August 2025.
  10. ^Michael, Randal (2008).Mastering Unix Shell Scripting (2nd ed.). Indianapolis, Indiana:Wiley. p. 3.ISBN 978-0-470-18301-4. Retrieved16 August 2025.UNIX is case sensitive. Because UNIX is case sensitive, our shell scripts are also case sensitive.
  11. ^"GNU Bash Manual: 8.2.1 Readline Bare Essentials".GNU Project.Free Software Foundation. Retrieved8 August 2025.
  12. ^"GNU Bash Manual: 8.5 Readline vi mode".GNU Project.Free Software Foundation, Inc. Retrieved8 August 2025.
  13. ^Rippee, Scott (5 October 2012)."Getting started with BASH: A Bash Tutorial".hypexr.org. Archived fromthe original on 2 March 2021. Retrieved8 August 2025.
  14. ^"Bash Reference Manual, D.2 Index of Shell Reserved Words". Retrieved18 August 2025.
  15. ^abcd"Bash Reference Manual".www.gnu.org.
  16. ^"Arrays (Bash Reference Manual)".www.gnu.org.
  17. ^Huber, Mathias."Bash 4.0 Introduces Associative Arrays » Linux Magazine".Linux Magazine.
  18. ^ab"3.2.1. The path".Introduction to Linux.Linux Documentation Project. Retrieved13 August 2025.
  19. ^"Modular data structures in C".dartmouth.edu.Dartmouth University. Retrieved15 August 2025.
  20. ^"4.1 Bourne Shell Builtins".gnu.org.Free Software Foundation. Retrieved26 August 2025.
  21. ^abStevens, Al (1 July 2021)."I Almost Get a Linux Editor and Compiler".Dr. Dobbs' Journal. Archived fromthe original on 2 March 2021. Retrieved8 August 2025.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.
  22. ^"Bash reference manual, 6.2 Bash startup files".GNU Project.Free Software Foundation. Retrieved12 August 2025.
  23. ^abCooper, Mendel. "36.9: Portability Issues".Advanced Bash Scripting Guide.Linux Documentation Project.Archived from the original on 27 January 2012. Retrieved8 August 2025 – via The Public's Library and Digital Archive.
  24. ^Ramey, Chet."6.11 Bash and POSIX".Case Western Reserve University. Retrieved8 August 2025.
  25. ^ab"10 – Files".Debian Policy Manual v4.5.0.2. Debian Project.Archived from the original on 12 May 2020. Retrieved11 May 2020.
  26. ^abcheckbashisms(1) – Linux General CommandsManual from ManKier.com
  27. ^abshellcheck(1) – Linux General CommandsManual from ManKier.com
  28. ^GNU Project. "11: Portable Shell".Autoconf.Free Software Foundation.Archived from the original on 2 March 2021. Retrieved20 January 2020.
  29. ^GNU Project. "B.1 Implementation Differences from the SVR4.2 Shell".Bash Reference Manual.Free Software Foundation. Retrieved13 August 2025.In a questionable attempt at security, the SVR4.2 shell, when invoked without the -p option, will alter its real and effective UID and GID....
  30. ^GNU Project. "4.3.1 The Set Builtin".Bash Reference Manual.Free Software Foundation. Retrieved13 August 2025.In this mode, the $BASH_ENV and $ENV files are not processed, shell functions are not inherited from the environment, and the SHELLOPTS, BASHOPTS, CDPATH and GLOBIGNORE variables, if they appear in the environment, are ignored.
  31. ^ab"BASH Debugger".SourceForge. Retrieved18 August 2025.
  32. ^GNU Project. "6.12 Shell Compatibility Mode".Bash Reference Manual.Free Software Foundation. Retrieved5 August 2025.
  33. ^Seeset-v in the documentation.
  34. ^The Open Group."2.15 Special Builtins: colon - null utility".opengroup.org. Base Specifications Issue 8: IEEE Std 1003.1-2024. Retrieved8 August 2025.
  35. ^"Bash Reference Manual: 7.1 Job Control Basics".Free Software Foundation, Inc.GNU Project.Archived from the original on 15 March 2018. Retrieved8 August 2025.
  36. ^Michael, Randal (2008).Mastering Unix Shell Scripting, 2e. Wiley Publishing, Inc., Indianapolis, Indiana. p. 25.ISBN 978-0-470-18301-4. Retrieved16 August 2025.19 :: SIGSTOP :: Stop, usually Ctrl + z
  37. ^Newham, Cameron (29 March 2005).Learning the bash Shell: Unix Shell Programming. O'Reilly Media, Inc. p. 205.ISBN 978-0-596-55500-9. Retrieved16 August 2025.Use KILL only as a last resort!
  38. ^"dd(1)".www.man7.org. Retrieved19 October 2025.
  39. ^ab"Bash(1)".case.edu.Case Western Reserve University. Retrieved8 August 2025.
  40. ^"Sending and Trapping Signals".wooledge.org. Retrieved5 August 2025.
  41. ^Michael, Randal (2008).Mastering Unix Shell Scripting, 2e. Wiley Publishing, Inc., Indianapolis, Indiana. p. 20.ISBN 978-0-470-18301-4. Retrieved16 August 2025.In Korn shell theecho command recognizes these command options by default. In Bash shell we must add the-e switch to theecho command,echo-e"\n" for one new line.
  42. ^"Bash Reference Manual: 3.7.3: Command Execution Environment".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  43. ^"Bash Reference Manual, 6.6 Aliases".Free Software Foundation, Inc.GNU Project. Retrieved14 August 2025.Aliases allow a string to be substituted for a word that is in a position in the input where it can be the first word of a simple command. Aliases have names and corresponding values that are set and unset using the alias and unalias builtin commands.
  44. ^"alias - define or display aliases".opengroup.org. The Open Group. Retrieved14 August 2025.
  45. ^Cooper, Mendel."Advanced Bash Scripting Guide, Ch 25. Aliases".Linux Documentation Project. Retrieved14 August 2025.
  46. ^"Commands and Arguments: Aliases".wooledge.org. Retrieved14 August 2025.
  47. ^"Compound Commands: Aliases".wooledge.org. Retrieved14 August 2025.
  48. ^"Bash Reference Manual, 3.3 Shell Functions".Free Software Foundation, Inc.GNU Project. Retrieved14 August 2025.Shell functions are a way to group commands for later execution using a single name for the group. They are executed just like a "regular" simple command. When the name of a shell function is used as a simple command name, the shell executes the list of commands associated with that function name. Shell functions are executed in the current shell context; there is no new process created to interpret them.
  49. ^"2.9.5 Function Definition Command".opengroup.org. The Open Group. Retrieved14 August 2025.
  50. ^Cooper, Mendel."Advanced Bash Scripting Guide, Ch 24. Functions".Linux Documentation Project. Retrieved14 August 2025.
  51. ^"Compound Commands, 4. Functions".wooledge.org. Retrieved14 August 2025.
  52. ^"Bash Programming, 2. Basic Concepts, 7. Functions".wooledge.org. Retrieved14 August 2025.
  53. ^"Bash Weaknesses, 13. Functions".wooledge.org. Retrieved14 August 2025.
  54. ^"Bash Reference Manual: 4.1: Bourne Shell Builtins".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  55. ^"Bash Reference Manual: 4.3.1: The Set Builtin".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  56. ^"bug-bash archives, Re: Document that set -v inside case statements is special".bug-bash (Mailing list).GNU Project. 20 April 2021. Retrieved8 August 2025.
  57. ^ab"Bash changes".bash-hackers.org. Archived fromthe original on 23 September 2019. Retrieved8 August 2025.
  58. ^"Glossary of Coding Terms for Beginners: iteration".syracuse.edu.Syracuse University. 13 January 2020. Retrieved15 August 2025.
  59. ^"compound - noun (1)".merriam-webster.com.Merriam-Webster's Collegiate Dictionary. Retrieved15 August 2025.
  60. ^Stephen R Bourne (12 June 2015)."Early days of Unix and design of sh"(PDF).bsdcan.org. BSDcan 2015: The Technical BSD Conference. Retrieved8 August 2025.
  61. ^"Advanced Bash Scripting Guide: 37.2: Bash, version 3".Linux Documentation Project. Section 37.2 (Bash, version 3).Archived from the original on 5 May 2017. Retrieved5 March 2017.
  62. ^"GNU Bash Manual: 3.2.5.2: Conditional Constructs".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  63. ^"Bash Reference Manual, 3.2.6 Coprocesses".Free Software Foundation, Inc.GNU Project. Retrieved15 August 2025.
  64. ^Mallett, Andrew (24 December 2015).Mastering Linux Shell Scripting. Packt Publishing, Ltd. p. 56.ISBN 978-1-78439-759-3. Retrieved16 August 2025.Learning this now can save us a lot of pain and heartache later, especially....
  65. ^"Bash Reference Manual: 5.3.1 Brace Expansion".Free Software Foundation, Inc.GNU Project.Archived from the original on 15 March 2018. Retrieved8 August 2025.
  66. ^"Advanced Bash Scripting Guide: 37.3: Bash, version 4".Linux Documentation Project.Archived from the original on 1 July 2018. Retrieved8 August 2025.
  67. ^"Update bash to version 4.0 on OSX".apple.stackexchange.com.Archived from the original on 25 June 2018. Retrieved8 August 2025.
  68. ^"Bash Reference Manual: 6.7: Arrays".Free Software Foundation, Inc.GNU Project.Archived from the original on 11 July 2018. Retrieved8 August 2025.
  69. ^"Bash Reference Manual, 3.1.2.5 Locale-Specific Translation".Free Software Foundation, Inc.Free Software Foundation. Retrieved16 August 2025.Prefixing a double-quoted string with a dollar sign$, such as$"hello, world", causes the string to be translated according to the current locale. The gettext infrastructure performs the lookup and translation, using the$LC_MESSAGES,$TEXTDOMAINDIR, and$TEXTDOMAIN shell variables.
  70. ^"The Bash Parser".wooledge.org. Retrieved15 August 2025.
  71. ^Ramey, Chet."The Architecture of Open Source Applications (Volume 1): The Bourne-Again Shell".aosabook.org. Retrieved15 August 2025.
  72. ^"Bash Reference Manual: 9.2: Bash History Builtins".Free Software Foundation, Inc.GNU Project.Archived from the original on 15 September 2019. Retrieved8 August 2025.
  73. ^"Bash Reference Manual: 8.6: Programmable Completion".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  74. ^"Bash Reference Manual: 8.6 Programmable completion".case.edu.Case Western Reserve University. Retrieved8 August 2025.
  75. ^"Index of /gnu/bash".swin.edu.au. Swinburne University of Technology.Archived from the original on 8 March 2020. Retrieved8 August 2025.
  76. ^ab"Advanced Bash Scripting Guide: Appendix J: An Introduction to Programmable Completion".Linux Documentation Project. Retrieved21 January 2022.
  77. ^ab"Bash".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  78. ^abFree Software Foundation."GNU Bash manual".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  79. ^"Bash Reference Manual".case.edu.Case Western Reserve University. Retrieved8 August 2025.
  80. ^"git: index: bash.git".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  81. ^"GNU Coreutils manual v.9.7, 15.2 printf: Format and print data".Free Software Foundation, Inc.GNU Project. Retrieved11 August 2025.
  82. ^"GNU Bash Manual: 1.1: What is Bash?".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  83. ^Open Group."POSIX 2024".Free Software Foundation, Inc. Retrieved30 July 2025.
  84. ^"The Open Group Base Specifications Issue 7, 2018 edition".opengroup.org.
  85. ^ab"The GNU Bourne-Again Shell, Top Page".case.edu.Case Western Reserve University. Retrieved8 August 2025.
  86. ^"Frequently Asked Questions".case.edu.Case Western Reserve University. Retrieved8 August 2025.
  87. ^"CVE-2024-2448: Authenticated Command Injection In Progress Kemp LoadMaster".rhinosecuritylabs.com. Rhino Security Labs, Inc. 23 April 2024. Retrieved17 August 2025.
  88. ^"CGI-BIN Specific Vulnerabilities".ucdavis.edu.University of California, Davis. January 1999. Retrieved17 August 2025.
  89. ^"CGI Security".BITS: computing and communications news. Los Alamos National Laboratory. March 1996. Archived fromthe original on 16 April 2000. Retrieved17 August 2025.
  90. ^"Eval command and security issues".wooledge.org.Archived from the original on 21 July 2025. Retrieved17 August 2025.
  91. ^"Input Validation Cheat Sheet".owasp.org.OWASP. Retrieved17 August 2025.
  92. ^Juliana, Cino (10 June 2017)."Linux bash exit status and how to set exit status in bash - Techolac".techolac.com.Archived from the original on 21 June 2019. Retrieved21 June 2019.
  93. ^Leyden, John (24 September 2014)."Patch Bash NOW: 'Shell Shock' bug blasts OS X, Linux systems wide open".theregister.co.uk.The Register.Archived from the original on 16 October 2014. Retrieved25 September 2014.
  94. ^Perlroth, Nicole (25 September 2014)."Security Experts Expect 'Shellshock' Software Bug in Bash to Be Significant".The New York Times.Archived from the original on 5 April 2019. Retrieved25 September 2014.
  95. ^Seltzer, Larry (29 September 2014)."Shellshock makes Heartbleed look insignificant".zdnet.com.ZDNet.Archived from the original on 14 May 2016.
  96. ^Sidhpurwala, Huzaifa (24 September 2014)."Bash specially-crafted environment variables code injection attack".redhat.com.Red Hat.Archived from the original on 25 September 2014. Retrieved25 September 2014.
  97. ^Chazelas, Stephane (4 October 2014)."oss-sec mailing list archives".seclists.org.Archived from the original on 6 October 2014. Retrieved4 October 2014.
  98. ^"Command Substitution (Bash Reference Manual)".www.gnu.org. Retrieved14 January 2026.
  99. ^"Advanced Bash Scripting Guide: 2.3: Debugging Bash scripts".Linux Documentation Project.Archived from the original on 4 November 2018. Retrieved8 August 2025.
  100. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. BASHPID. Retrieved8 August 2025.
  101. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. BASH_ARGC. Retrieved8 August 2025.
  102. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. BASH_ARGV. Retrieved8 August 2025.
  103. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. BASH_LINENO. Retrieved8 August 2025.
  104. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. BASH_REMATCH. Retrieved8 August 2025.
  105. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. BASH_SOURCE. Retrieved8 August 2025.
  106. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. BASH_XTRACEFD. Retrieved8 August 2025.
  107. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. EPOCHREALTIME. Retrieved8 August 2025.
  108. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. FUNCNAME. Retrieved8 August 2025.
  109. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. LINENO. Retrieved8 August 2025.
  110. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. PIPESTATUS. Retrieved8 August 2025.
  111. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. PPID. Retrieved8 August 2025.
  112. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. PS4. Retrieved8 August 2025.
  113. ^
  114. ^"Bash Reference Manual: 3.4.2: Special Parameters".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  115. ^"Shell Command Language".opengroup.org.
  116. ^ab
  117. ^abcde"Bash(1), Shell builtin commands".case.edu.Case Western Reserve University. Retrieved8 August 2025.
  118. ^ab"Bourne Shell Builtins (Bash Reference Manual)".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  119. ^"Bash Reference Manual: 5.2: Bash Variables".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  120. ^"Bash(1), Special parameters".case.edu.Case Western Reserve University. Retrieved8 August 2025.
  121. ^"The Shopt Builtin (Bash Reference Manual)".Free Software Foundation, Inc.GNU Project. Retrieved8 August 2025.
  122. ^
  123. ^"Debian -- Details of package devscripts in sid".debian.org.
  124. ^"Kcov - code coverage".github.io.
  125. ^"[Bashdb-devel] Re: [PATCH] fix bashdb script handling of tmp directory".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  126. ^"bashbug(1)".die.net. 21 October 2017. Archived fromthe original on 2 October 2018.
  127. ^"bashbug(1) Mac OS X Manual Page".apple.com. 4 June 2014. Archived fromthe original on 6 October 2014.
  128. ^"In Unix, what do some obscurely named commands stand for?".iu.edu. Indiana University. 5 February 2009. Archived fromthe original on 10 June 2010. Retrieved8 August 2025.
  129. ^Louis Pouzin (25 November 2000)."The Origin of the Shell".multicians.org.
  130. ^"The SHELL, A Global Tool for Calling and Chaining Procedures in the System"(PDF).mit.edu.
  131. ^Cerf, Vint (16 October 1969)."ASCII Format for Network Interchange".ietf.org. UCLA, Network Working Group. Retrieved8 August 2025.
  132. ^abStallman, Richard; Ramey, Chet (10 February 1988)."GNU + BSD = ?".google.com.Newsgroupcomp.unix.questions.Usenet: 2362@mandrill.CWRU.Edu.Archived from the original on 28 December 2021. Retrieved28 December 2021.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.
  133. ^Stallman, Richard (3 October 2010)."About the GNU Project".Free Software Foundation, Inc.GNU Project.Archived from the original on 24 April 2011. Retrieved8 August 2025.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.
  134. ^Fox, Brian; Tower Jr., Leonard H. (8 June 1989)."Bash is in beta release!".google.com.Newsgroupgnu.announce.Archived from the original on 4 May 2013. Retrieved28 October 2010.
  135. ^"Evolution of shells in Linux".ibm.com. IBM. 9 December 2011.
  136. ^Torvalds, Linus (26 August 1991)."What would you like to see most in Minix?".google.com.Newsgroupcomp.os.minix. Retrieved8 August 2025.To make things really clear - yes I can run gcc on it, and bash, and most of the gnu [bin/file]utilities
  137. ^"January 1993 GNU's Bulletin".google.com.Newsgroupgnu.announce. 20 April 1993.Usenet: gnusenet930421bulletin@prep.ai.mit.edu.Archived from the original on 2 March 2021. Retrieved28 October 2010.
  138. ^Ramey, Chet (1 August 1994)."Bash – the GNU shell (Reflections and Lessons Learned)".linuxjournal.com.Linux Journal.Archived from the original on 5 December 2008. Retrieved13 November 2008.
  139. ^Ramey, Chet (31 October 2010),"Dates in your Computerworld interview",scribd.com,archived from the original on 20 July 2012, retrieved31 October 2010
  140. ^
  141. ^Bresnahan, Christine; Blum, Richard (April 2015).CompTIA Linux+ Powered by Linux Professional Institute Study Guide: Exam LX0-103 and Exam LX0-104 (3rd ed.). John Wiley & Sons, Inc. p. 5.ISBN 978-1-119-02122-3.Archived from the original on 2 March 2021. Retrieved6 June 2016.In Linux, most users run bash because it is the most popular shell.
  142. ^Danesh, Arman; Jang, Michael (February 2006).Mastering Linux. John Wiley & Sons, Inc. p. 363.ISBN 978-0-7821-5277-7.Archived from the original on 2 March 2021. Retrieved6 June 2016.The Bourne Again Shell (bash) is the most common shell installed with Linux distributions.
  143. ^ab"Debian Wiki: Shell".debian.org.
  144. ^Ramey, Chet (14 September 2000)."Re: Line-Edit mode is lost if "set -o vi" is in any files sourced on login".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  145. ^Ramey, Chet (9 April 2001)."Bash-2.05 available for FTP".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  146. ^Essential Mac OS S Panther Server Administration, pg 189
  147. ^Foster-Johnson, Eric; Welch, John C.; Anderson, Micah (April 2005).Beginning Shell Scripting. John Wiley & Sons, Inc. p. 6.ISBN 978-0-7645-9791-6.Archived from the original on 2 March 2021. Retrieved8 August 2025.Bash is by far the most popular shell and forms the default shell on Linux and Mac OSX systems.
  148. ^"Bash-3.0 available for FTP".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  149. ^"Bash-3.1 released".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  150. ^"Bash-3.2 available for FTP".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  151. ^"Bash-4.0 available for FTP".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  152. ^"Bash-4.1 available for FTP".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  153. ^"Bash-4.2 available for FTP".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  154. ^"User Environment Feature Changes".oracle.com.Oracle Corporation.Archived from the original on 12 June 2018. Retrieved8 August 2025.
  155. ^"Bash-4.3 available for FTP".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  156. ^"CVE-2014-6271".cve.org. Retrieved8 August 2025.GNU Bash through 4.3 processes trailing strings after function definitions in the values of environment variables, which allows remote attackers to execute arbitrary code via a crafted environment, as demonstrated by vectors involving the ForceCommand feature in OpenSSH sshd, the mod_cgi and mod_cgid modules in the Apache HTTP Server, scripts executed by unspecified DHCP clients, and other situations in which setting the environment occurs across a privilege boundary from Bash execution, aka "ShellShock."
  157. ^"CVE-2014-7169".cve.org. Retrieved8 August 2025.
  158. ^"Bash 3.0 Official Patch 1".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  159. ^Briegel, Armin (5 June 2019)."Moving to zsh".scriptingosx.com. Retrieved8 August 2025.
  160. ^"Apple Support – Use zsh as the default shell on your Mac".apple.com.Archived from the original on 2 December 2019. Retrieved8 August 2025.
  161. ^Warren, Tom (4 June 2019)."Apple replaces bash with zsh as the default shell in macOS Catalina".theverge.com.The Verge.Archived from the original on 10 June 2019. Retrieved8 August 2025.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.
  162. ^Hughes, Matthew (4 June 2019)."Why does macOS Catalina use Zsh instead of Bash? Licensing".The Next Web.Archived from the original on 31 December 2020. Retrieved8 August 2025.
  163. ^"Bash-5.0 release available".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  164. ^"Bash-5.1 release available".bug-bash (Mailing list).GNU Project. Retrieved8 August 2025.
  165. ^"shell.c",Free Software Foundation, Inc.,GNU Project, 29 August 1996,archived from the original on 28 September 2018, retrieved8 August 2025
  166. ^"Command-line shell".archlinux.org. 5 February 2025. Retrieved8 August 2025.
  167. ^Hanny Helal (7 January 2015)."Gtkdialog – Create Graphical (GTK+) Interfaces and Dialog Boxes Using Shell Scripts in Linux".tecmint.com. Tecmint. Retrieved18 August 2025.
  168. ^abKristian Kißling (2009)."Adding graphic elements to your scripts with Zenity and KDialog".linux-magazine.com. Linux Magazine. Issue 99. Retrieved18 August 2025.
  169. ^"Bash Shell Scripting/Whiptail".wikibooks.org. WikiMedia. Retrieved18 August 2025.
  170. ^Dmitri Popov (12 March 2012)."Dress Up Bash Scripts with YAD".linux-magazine.com. Linux Magazine. Retrieved18 August 2025.
  171. ^Pete Metcalfe (2021)."Create GUI dialogs in one line of code".linux-magazine.com. Linux Magazine. Issue 247. Retrieved18 August 2025.
History
Licenses
Software
Contributors
Other topics
International
National
Other
Retrieved from "https://en.wikipedia.org/w/index.php?title=Bash_(Unix_shell)&oldid=1333189994"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp