Bash (Unix shell): Difference between revisions

Content deleted Content added
Data structures: Change subsection name
m fix quot; repair
 
(47 intermediate revisions by 7 users not shown)
Line 1:
{{Short description|GNU replacement for the Bourne shell}}
{{multiple issues|
<!--{{In use| date = 2025-08-12| section = entire article}}-->
{{Under constructionhow-to|date=August 2025-08-12|nosection=yes}}
{{More refs|date=August 2025}}
{{Over-quotation|date=August 2025}}
}}
{{Use dmy dates|date=March 2014}}
{{Infobox software
Line 23 ⟶ 25:
| url = https://www.gnu.org/software/bash/
| url-status = live
| website = gnu[[Free Software Foundation, Inc.org]]
}}
</ref>
Line 106 ⟶ 108:
| title = GNU in a Nutshell
| url = https://www.gnu.org/gnu/about-gnu.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}
|
Line 124 ⟶ 126:
| title = GNU Software
| url = https://www.gnu.org/software/software.en.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}
}}
Line 191 ⟶ 193:
| title = GNU's Bulletin, vol 1 no 7, June, 1989 :: GNU Project Status Report
| url = https://www.gnu.org/bulletins/bull7.html#SEC14
| website = gnu[[Free Software Foundation, Inc.org]]
}}
</ref><ref>
Line 207 ⟶ 209:
| url = https://www.gnu.org/gnu/thegnuproject.html
| url-status = live
| website = gnu[[Free Software Foundation, Inc.org]]
}}
|
Line 265 ⟶ 267:
| url = https://developer.mozilla.org/en-US/docs/Glossary/Character
| website = mozilla.org
| date = 11 July 2025
}}
</ref>
Line 333 ⟶ 336:
| quote = UNIX is case sensitive. Because UNIX is case sensitive, our shell scripts are also case sensitive.
| title = Mastering Unix Shell Scripting, 2e
| url = https://books.google.com/books?hl=en&lr=&id=uI7C2BDF6F0C
}}
</ref>
Line 362 ⟶ 365:
BCPL is a precursor of the [[C (programming language) |C programming language]], in which Bash is written.
In [[C++]], a descendant of C, it's also true that "arrays start indexing from element 0."<ref>
{{Cite webbook
| access-date = 25 August 2025
| author = Graham M. Seed
Line 370 ⟶ 373:
| publisher = [[Springer Science+Business Media]]
| title = An Introduction to Object-Oriented Programming in C++, 7.4 Array Indexing
| url = https://books.google.com/books?id=_lqj98AsnGAC&q=zeroth+element&pg=PA195#v=snippet&q=zeroth%20element&f=false
| isbn = 978-1-85233-450-5
| website = books.google.com
}}
</ref>
The array's name and index number are a synonym for the data's ___location in memory.<ref>
{{Cite webbook
| access-date = 25 August 2025
| author = Graham M. Seed
Line 383 ⟶ 386:
| quote = The name of an array is a synonym for the memory ___location of the array.
| title = An Introduction to Object-Oriented Programming in C++, 7.12.1 One-Dimensional Arrays
| url = https://books.google.com/books?id=_lqj98AsnGAC&q=zeroth+element&pg=PA210#v=snippet&q=zeroth%20element&f=false
| isbn = 978-1-85233-450-5
| website = books.google.com
}}
</ref>
Line 461 ⟶ 464:
| title = GNU Bash Manual: 8.2.1 Readline Bare Essentials
| url = https://www.gnu.org/software/bash/manual/html_node/Readline-Bare-Essentials.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}
</ref>
Line 483 ⟶ 486:
| title = GNU Bash Manual: 8.5 Readline vi mode
| url = https://www.gnu.org/software/bash/manual/html_node/Readline-vi-Mode.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref><ref>
{{Cite web
Line 497 ⟶ 500:
}}</ref>
 
=== TokenizationSyntax <span class="anchor" id="Syntax"></span><span class="anchor" id="Tokens"></span><span class="anchor" id="Metacharacters"></span><span class="anchor" id="Operators"></span><span class="anchor" id="Words"></span><span class="anchor" id="Names"></span> ===
 
<!-- Important concepts:
: <syntaxhighlight lang = text>
[] stream of characters
Tokens
[] delineate full commandlines (newline, semi-colon)
\_ Blanks
[] division into commands and parts of commands (optargs)
\_ Operators (Ops)
[] uses metacharacters
\_ Control Ops
-->
\_ Redirection Ops
<syntaxhighlight lang = text>
\_ Words
"Tokens"
\_ Reserved Words
\_ "Blanks"
\_ Names
\_ "Operators" (Ops)
\_ "Control Ops"
\_ "Redirection Ops"
\_ "Words"
\_ "Reserved Words"
\_ "Names"
</syntaxhighlight>
 
{{Blockquote
When Bash reads a full commandline, the complete string is broken down according to a certain set of rules into individual units called ''tokens.''
| syn{{dot}}tax '''1 a :''' the way in which linguistic elements (such as words) are put together to form constituents (such as phrases or clauses) '''b :''' the part of grammar dealing with this<ref>
''Tokens'' are identified using, and separated from each other using ''metacharacters.''
{{Cite web
| access-date = 25 August 2025
| title = syntax, noun
| url = https://www.merriam-webster.com/dictionary/syntax
| website = merriam-webster.com
}}
</ref>
| author = Merriam-Webster Dictionary
}}
 
 
When Bash reads a ''full commandline,'' the complete string is broken down according to a certain set of rules into individual units called ''"tokens."''
"Tokens" are identified using, and separated from each other using ''"metacharacters."'' (As of version 5.3:)
 
* The ten ''"metacharacters:"''
 
: {{Pre |‘space’ ‘tab’ ‘newline’ ‘|’ ‘&’ ‘;’ ‘(’ ‘)’ ‘<’ ‘>’}}
 
''"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 down ''full command strings'' into tokens or groups of tokens that ''do'' contain metacharacters as well asand tokens or groups of tokens that do ''not'' contain any metacharacters -- called ''"words."''
From there it further breaks ''words'' down into more specific, meaningful pieces like command names, variable assignment statements, etc.
 
* The two ''Blanks"blanks"''
 
: {{Pre |‘space’ ‘tab’}}
 
* ''"Operators"''
 
:* Eight of the twelve ''"control operators:"''
:* ''Control Operators''
 
:: <syntaxhighlight lang = text>
‘newline’ ‘||’ ‘&&’ ‘&’ ‘;’ ‘;;’ ‘;&’ ‘;;&|’ ‘||’ ‘|&&’ ‘(’ ‘)’ ...
</syntaxhighlight>
 
:* Five of the fourteen ''"redirection operators:"''
:* ''Redirection Operators''
 
:: <syntaxhighlight lang = text>
‘<’ ‘<>’ ‘>’ ‘>|’ ‘&>>’ ‘&>’ ‘>&’ ‘<&<’ ‘<<’ ‘<<-‘<<<’...
</syntaxhighlight>
 
A ''"word"'' is a sequence of (non-meta-) characters treated as a single unit by the shell.
A ''"reserved word"'' is a kind of a ''"word"'' that has a special meaning to the shell.<ref>
{{Cite web
| access-date = 18 August 2025
Line 548 ⟶ 570:
}}
</ref>
A ''"name"'' is a kind of a ''"word,"'' separate from ''reserved words'', which consists 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 called ''"identifiers,"'' may be used for naming variables and functions.
 
* ''"Words"''
 
:* Sixteen of the twenty-two ''"reserved words,"'' which may be characters or words:
:* ''Reserved Words''
 
:: <syntaxhighlight lang = bash>
‘!’ ‘[[’ ‘{’ ‘]]’ ‘}’ coproc case do done else elifin esac fi for functiondo done if inthen timeelif selectelse then untilfi while...
</syntaxhighlight>
 
:* ''"Names"'' may contain only these characters (in the English language):
 
:: <syntaxhighlight lang = text>
Line 565 ⟶ 587:
</syntaxhighlight>
 
In thisthe following example of a full command string, ''metacharacters'' have an comma placed above them, {{Code| ,}}, ''reserved words'' have an carrat placed beneath them, {{Code| ^}}, and other ''tokens'' have a backtick placed also beneath them, {{Code| `}}.
 
: <syntaxhighlight lang = console>
Line 572 ⟶ 594:
$ # ^^ ```` ``` ^^^^ ``````` ^^
</syntaxhighlight>
 
=== Subshells <span class="anchor" id="Subshells"></span> ===
 
<!-- Important concepts:
[x] Subshells
[x] Process and environment info, ie, parent/child, exact copy, etc
-->
 
A "subshell" is an additional instance of the shell which has been intitialized 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 in ''single parentheses''.
 
: <syntaxhighlight lang = console>
$ echo foo
foo
$ ( echo foo )
foo
$
</syntaxhighlight>
 
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.
 
=== Expansion <span class="anchor" id="Expansion"></span> ===
 
<!-- Important concepts:
[]
-->
"Expansion" is a crucial concept in Unix-like shells. See [[String interpolation]].
 
Line 641 ⟶ 689:
| title = Bash Reference Manual, 3.4 Shell Parameters
| url = https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameters
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
 
Line 652 ⟶ 700:
| title = Bash reference manual, 3.4.1 Positional Parameters
| url = https://www.gnu.org/software/bash/manual/bash.html#Positional-Parameters
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
*** "$1" "$2" "$3" ... "${10}" "${11}" "${12}" - "The parentheses are required when there are two or more digits."<ref name = multics_ec>
Line 676 ⟶ 724:
| title = Bash reference manual, 3.4.2 Special Parameters
| url = https://www.gnu.org/software/bash/manual/bash.html#Special-Parameters
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref><ref>
{{Cite web
Line 697 ⟶ 745:
| title = Bash reference manual, 5.1 Bourne Shell Variables
| url = https://www.gnu.org/software/bash/manual/bash.html#Bourne-Shell-Variables
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
***** "$HOME"
Line 706 ⟶ 754:
| title = Bash reference manual, 5.2 Bash Variables
| url = https://www.gnu.org/software/bash/manual/bash.html#Bash-Variables
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
** Scripting variables: signified by all lower case letters or by CamelCase
Line 716 ⟶ 764:
| title = Bash reference manual, 6.7 Arrays
| url = https://www.gnu.org/software/bash/manual/bash.html#Arrays
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref><ref>
{{Cite web
Line 821 ⟶ 869:
| title = Introduction to Linux, Ch. 3 About files and the filesystem, 3.1. General overview of the Linux file system, 3.1.1 Files
| url = https://tldp.org/LDP/intro-linux/html/sect_03_02.html#sect_03_02_02
| website = tldp.org[[Linux Documentation Project]]
}}</ref>{{efn
| This description does not apply to [[Microsoft Windows |Windows]]-based operating systems.
Line 848 ⟶ 896:
| title = Introduction to Linux, Ch. 3 About files and the filesystem, 3.4 File security, 3.4.2.3. The file mask
| url = https://tldp.org/LDP/intro-linux/html/sect_03_04.html
| website = tldp.org[[Linux Documentation Project]]
}}</ref>
 
Line 875 ⟶ 923:
| title = Introduction to Linux, Ch. 3 About files and the filesystem, 3.2 Orientation in the filesystem, 3.2.2 Absolute and relative paths
| url = https://tldp.org/LDP/intro-linux/html/sect_03_02.html#sect_03_02_02
| website = tldp.org[[Linux Documentation Project]]
}}</ref>
When the kernel searches for a directory, the starting point is the leftmost character of directory name.
Line 932 ⟶ 980:
| title = Introduction to Linux, Ch. 3 About files and the filesystem, 3.2 Orientation in the filesystem, 3.2.1 The path
| url = https://tldp.org/LDP/intro-linux/html/sect_03_02.html#sect_03_02_01
| website = tldp.org[[Linux Documentation Project]]
}}</ref>
 
Line 1,114 ⟶ 1,162:
[ ] scripts execute the contents of a file in a subshell
-->
 
With the {{code| source}}, or synonymous {{code| .}}, command, Bash can read and execute shell commands from files which are not marked as executable, which do not have hash-bangs, and which do not have the file extension {{mono| .sh}}.
With the {{code| source}}, or synonymous {{code| .}} command, Bash reads and executes shell commands from any text file by name.<ref>
Such files are known as "source files" or "dotfiles."
{{Cite web
In Unix, file names which begin with a "dot," such as {{mono| ~/.bashrc}} are considered "[[Hidden file and hidden directory |hidden files]]."
| access-date = 26 August 2025
| publisher = [[Free Software Foundation, Inc.]]
| title = 4.1 Bourne Shell Builtins
| url = https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html
| website = gnu.org
}}
</ref>
 
=== Login and non-login shells <span class="anchor" id="Login and non-login shells"></span><span class="anchor" id="Login shells"></span><span class="anchor" id="Non-login shells"></span> ===
Line 1,179 ⟶ 1,234:
| title = Bash reference manual, 6.2 Bash startup files
| url = https://www.gnu.org/software/bash/manual/bash.html#Bash-Startup-Files-1
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
* How bash is called
Line 1,242 ⟶ 1,297:
| url = https://tldp.org/LDP/abs/html/portabilityissues.html
| url-status = live
| website = tldp.org[[Linux Documentation Project]]
}}</ref>
To cause a script to be initialized in POSIX mode, one would use the either the hashbang {{Code| #! /bin/env sh}} or the less portable {{Code| #!/bin/sh}}.
Line 1,333 ⟶ 1,388:
| url = https://www.gnu.org/software/autoconf/manual/html_node/Portable-Shell.html
| url-status = live
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
 
Line 1,352 ⟶ 1,407:
| title = Bash Reference Manual, B.1 Implementation Differences from the SVR4.2 Shell
| url = https://www.gnu.org/software/bash/manual/bash.html#Implementation-Differences-From-The-SVR4_002e2-Shell
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref> It can be enabled with {{Code| set -p| bash}} and disabled with {{Code| set +p| bash}}.<ref>
{{Cite web
Line 1,360 ⟶ 1,415:
| title = Bash Reference Manual, 4.3.1 The Set Builtin
| url = https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref> When privileged mode is enabled, the {{Code| $SHELLOPTS| bash}} shell variables includes the string, "privileged."
 
Line 1,389 ⟶ 1,444:
| title = Bash Reference Manual, 6.12 Shell Compatability Mode
| url = https://www.gnu.org/software/bash/manual/bash.html#Shell-Compatibility-Mode
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| author = Bash Reference Manual, 6.12 Shell Compatability Mode
Line 1,563 ⟶ 1,618:
| url = https://www.gnu.org/software/bash/manual/bash.html#index-background
| url-status = live
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
A list of all processes, both in the background and stopped, can be achieved by running {{mono|jobs}}:
Line 1,695 ⟶ 1,750:
| quote = 19 :: SIGSTOP :: Stop, usually Ctrl + z
| title = Mastering Unix Shell Scripting, 2e
| url = https://books.google.com/books?hl=en&lr=&id=uI7C2BDF6F0C
}}</ref>
When a process receives a SIGKILL, the process terminates immediately and messily.
Line 1,708 ⟶ 1,763:
| quote = Use KILL only as a last resort!
| title = Learning the bash Shell: Unix Shell Programming
| isbn = 978-0-596-55500-9
| url = https://books.google.com/books?hl=en&lr=&id=dzBCH3x6fYEC
| url = https://books.google.com/books?id=dzBCH3x6fYEC
}}</ref>
The SIGKILL signal cannot be blocked or handled.
Line 1,779 ⟶ 1,835:
| quote = In Korn shell the {{Mono |echo}} command recognizes these command options by default. In Bash shell we must add the {{Mono |-e}} switch to the {{Mono |echo}} command, {{Code| echo -e "\n"| bash}} for one new line.
| title = Mastering Unix Shell Scripting, 2e
| url = https://books.google.com/books?hl=en&lr=&id=uI7C2BDF6F0C
}}</ref>
The list of options is not uniform across implementations, though {{mono|echo}} and {{mono|printf}} are both specified by POSIX.
Line 1,887 ⟶ 1,943:
| title = Bash Reference Manual: 3.7.3: Command Execution Environment
| url = https://www.gnu.org/software/bash/manual/html_node/Command-Execution-Environment.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
* Shell and [[Session (computer science)|session]] startup files such as {{Code| ~/.bashrc}} and {{Code| ~/.profile}} (i.e., [[Hidden file and hidden directory|dotfiles]]);
Line 1,960 ⟶ 2,016:
| title = Bash Reference Manual, 6.6 Aliases
| url = https://www.gnu.org/software/bash/manual/html_node/Aliases.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref><ref>
{{Cite web
Line 1,975 ⟶ 2,031:
| title = Advanced Bash Scripting Guide, Ch 25. Aliases
| url = https://tldp.org/LDP/abs/html/abs-guide.html#ALIASES
| website = tldp.org[[Linux Documentation Project]]
}}</ref><ref>
{{Cite web
Line 2,033 ⟶ 2,089:
| title = Bash Reference Manual, 3.3 Shell Functions
| url = https://www.gnu.org/software/bash/manual/html_node/Shell-Functions.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref><ref>
{{Cite web
Line 2,048 ⟶ 2,104:
| title = Advanced Bash Scripting Guide, Ch 24. Functions
| url = https://tldp.org/LDP/abs/html/abs-guide.html#FUNCTIONS
| website = tldp.org[[Linux Documentation Project]]
}}</ref><ref>
{{Cite web
Line 2,093 ⟶ 2,149:
| title = Bash Reference Manual: 4.1: Bourne Shell Builtins
| url = https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
*** {{mono|cd}}, {{mono|pwd}}, etc.
Line 2,101 ⟶ 2,157:
| publisher = [[GNU Project]]
| title = Bash Reference Manual: 4.3.1: The Set Builtin
| url = https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
| website = [[Free Software Foundation, Inc.]]
/software/bash/manual/html_node/The-Set-Builtin.html
| website = gnu.org
}}</ref>
*** Xtrace: [ {{Code| set -x| bash}} | {{Code| set -o xtrace| bash}} ]. The shell's primary means of debugging. Both xtrace and verbose can be turned off at the same time with the command {{Code| set -| bash}}.
Line 2,280 ⟶ 2,335:
-->
{{Blockquote
| ITERATION: Sometimes programs are repeated indefinitely or until a specific outcome is reached. Each execution of the instructions is an “iteration"iteration."<ref>
{{Cite web
| access-date = 15 August 2025
Line 2,287 ⟶ 2,342:
| url = https://onlinegrad.syracuse.edu/blog/coding-terms-for-beginners/
| website = syracuse.edu
| date = 13 January 2020
}}</ref>
| author =
Line 2,366 ⟶ 2,422:
| url = https://www.tldp.org/LDP/abs/html/bashver3.html#BASH3REF
| url-status = live
| website = tldp.org[[Linux Documentation Project]]
}}</ref>
Regexp matching is limited to strings on the right side of the <CODE>=~</CODE> operator in the {{Code| [[..]]}} extended test construct.<ref>
Line 2,374 ⟶ 2,430:
| title = GNU Bash Manual: 3.2.5.2: Conditional Constructs
| url = https://www.gnu.org/software/bash/manual/bash.html#index-_005b_005b
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
 
Line 2,394 ⟶ 2,450:
| title = Bash Reference Manual, 3.2.6 Coprocesses
| url = https://www.gnu.org/software/bash/manual/bash.html#Coprocesses
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| author = Bash Reference Manual, 3.2.6 Coprocesses
Line 2,419 ⟶ 2,475:
| quote = Learning this now can save us a lot of pain and heartache later, especially....
| title = Mastering Linux Shell Scripting
| isbn = 978-1-78439-759-3
| url = https://books.google.com/books?hl=en&lr=&id=ITjlCwAAQBAJ
| url = https://books.google.com/books?id=ITjlCwAAQBAJ
}}</ref>
| author = Mastering Linux Shell Scripting, by Andrew Mallett
Line 2,473 ⟶ 2,530:
| url = https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html
| url-status = live
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
Generated results need not exist as files.
Line 2,535 ⟶ 2,592:
 
=== Tilde Expansion ===
{{Empty section|date=August 2025}}
 
Tilde expansion {{Code| ~}},
 
=== Parameter and variable expansion ===
Line 2,555 ⟶ 2,611:
| url = https://tldp.org/LDP/abs/html/bashver4.html
| url-status = live
| website = tldp.org[[Linux Documentation Project]]
}}</ref>
Bash 4.0{{efn|Bash 4 also switches its license to [[GNU General Public License#Version 3|GPL-3.0-or-later]].
Line 2,578 ⟶ 2,634:
| url = https://www.gnu.org/software/bash/manual/html_node/Arrays.html
| url-status = live
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref> They can be used to emulate multidimensional arrays.}}
* Parameter Expansion
Line 2,604 ⟶ 2,660:
| title = Bash Reference Manual, 3.1.2.5 Locale-Specific Translation
| url = https://www.gnu.org/software/bash/manual/bash.html#Locale-Translation
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
 
Line 2,716 ⟶ 2,772:
| url = https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Bash-History-Builtins
| url-status = live
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
This feature is available in interactive mode only.
Line 2,732 ⟶ 2,788:
| title = Bash Reference Manual: 8.6: Programmable Completion
| url = https://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
<ref name =bashfaq061/>
Line 2,761 ⟶ 2,817:
| title = Advanced Bash Scripting Guide: Appendix J: An Introduction to Programmable Completion
| url = https://tldp.org/LDP/abs/html/tabexpansion.html
| website = tldp.org[[Linux Documentation Project]]
}}</ref>
 
Line 2,782 ⟶ 2,838:
| title = Bash Reference Manual, 6.10 The Restricted Shell
| url = https://www.gnu.org/software/bash/manual/bash.html#The-Restricted-Shell-1
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
}}
Line 2,812 ⟶ 2,868:
| title = Bash
| url = https://www.gnu.org/savannah-checkouts/gnu/bash/bash.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}
</ref>
Line 2,822 ⟶ 2,878:
| title = GNU Bash manual
| url = https://www.gnu.org/software/bash/manual/index.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}
</ref><ref>
Line 2,842 ⟶ 2,898:
| title = git: index : bash.git
| url = https://git.savannah.gnu.org/cgit/bash.git/tree/doc/bash.0
| website = gnu[[Free Software Foundation, Inc.org]]
}}
</ref>
Line 2,856 ⟶ 2,912:
| title = GNU Coreutils manual v.9.7, 15.2 printf: Format and print data
| url = https://www.gnu.org/software/coreutils/manual/coreutils.html#printf_003a-Format-and-print-data
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
 
Line 2,868 ⟶ 2,924:
| title = GNU Bash Manual: 1.1: What is Bash?
| url = https://www.gnu.org/software/bash/manual/bash.html#What-is-Bash_003f
| website = gnu[[Free Software Foundation, Inc.org]]
}}
</ref>
Line 2,877 ⟶ 2,933:
| title = POSIX 2024
| url = https://pubs.opengroup.org/onlinepubs/9799919799/
| website = gnu[[Free Software Foundation, Inc.org]]
}}
</ref>
Line 2,923 ⟶ 2,979:
It is recommended to use {{mono|sudo}} on a per-command basis instead.
 
=== CGI Scriptsscripts ===
 
CGI scripts are a significant source of vulnerability.<ref>
Do not use Shell for CGI scripts. You have been warned.<ref>
{{Cite web
| access-date = 17 August 2025
Line 2,982 ⟶ 3,038:
| author = OWASP Input Validation Cheat Sheet
}}
 
=== Command injection ===
 
* CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')<ref>
{{Cite web
| access-date = 17 August 2025
| publisher = [[Mitre Corporation |The MITRE Corporation]]
| title = CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')
| url = https://cwe.mitre.org/data/definitions/77.html
| website = mitre.org
}}</ref>
 
* CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')<ref>
{{Cite web
| access-date = 17 August 2025
| publisher = [[Mitre Corporation |The MITRE Corporation]]
| title = CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
| url = https://cwe.mitre.org/data/definitions/78.html
| website = mitre.org
}}</ref>
 
* CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection')<ref>
{{Cite web
| access-date = 17 August 2025
| publisher = [[Mitre Corporation |The MITRE Corporation]]
| title = CWE-88: Improper Neutralization of Argument Delimiters in a Command ('Argument Injection')
| url = https://cwe.mitre.org/data/definitions/88.html
| website = mitre.org
}}</ref>
 
Clearlisting is more effective than blocklisting.
 
* CWE-184: Incomplete List of Disallowed Inputs<ref>
{{Cite web
| access-date = 17 August 2025
| publisher = [[Mitre Corporation |The MITRE Corporation]]
| title = CWE-184: Incomplete List of Disallowed Inputs
| url = https://cwe.mitre.org/data/definitions/184.html
| website = mitre.org
}}</ref>
 
=== Path traversal ===
 
* CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')<ref>
{{Cite web
| access-date = 17 August 2025
| publisher = [[Mitre Corporation |The MITRE Corporation]]
| title = CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
| url = https://cwe.mitre.org/data/definitions/22.html
| website = mitre.org
}}</ref>
 
=== TOCTOU errors (Race conditions) ===
 
* CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition<ref>
{{Cite web
| access-date = 17 August 2025
| publisher = [[Mitre Corporation |The MITRE Corporation]]
| title = CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition
| url = https://cwe.mitre.org/data/definitions/367.html
| website = mitre.org
}}</ref>
 
The {{Code| mkdir| bash}} and {{Code| mktemp| bash}} commands are known to create directories / files in an [[ACID |atomic]] fashion.
 
=== Untrusted search PATH ===
 
* CWE-426: Untrusted Search Path<ref>
{{Cite web
| access-date = 17 August 2025
| publisher = [[Mitre Corporation |The MITRE Corporation]]
| title = CWE-426: Untrusted Search Path
| url = https://cwe.mitre.org/data/definitions/426.html
| website = mitre.org
}}</ref>
 
* CWE-427: Uncontrolled Search Path Element<ref>
{{Cite web
| access-date = 17 August 2025
| publisher = [[Mitre Corporation |The MITRE Corporation]]
| title = CWE-427: Uncontrolled Search Path Element
| url = https://cwe.mitre.org/data/definitions/427.html
| website = mitre.org
}}</ref>
 
* CWE-428: Unquoted Search Path or Element<ref>
{{Cite web
| access-date = 17 August 2025
| publisher = [[Mitre Corporation |The MITRE Corporation]]
| title = CWE-428: Unquoted Search Path or Element
| url = https://cwe.mitre.org/data/definitions/427.html
| website = mitre.org
}}</ref>
 
=== Abuse of symlinks ===
 
* CWE-61: UNIX Symbolic Link (Symlink) Following<ref>
{{Cite web
| access-date = 17 August 2025
| publisher = [[Mitre Corporation |The MITRE Corporation]]
| title = CWE-61: UNIX Symbolic Link (Symlink) Following
| url = https://cwe.mitre.org/data/definitions/61.html
| website = mitre.org
}}</ref>
 
=== Sensitive information in error messages ===
 
* CWE-535: Exposure of Information Through Shell Error Message<ref>
{{Cite web
| access-date = 17 August 2025
| publisher = [[Mitre Corporation |The MITRE Corporation]]
| title = CWE-535: Exposure of Information Through Shell Error Message
| url = https://cwe.mitre.org/data/definitions/535.html
| website = mitre.org
}}</ref>
 
=== Shellshock ===
Line 3,196 ⟶ 3,137:
 
== Deprecated syntax <span class="anchor" id="Deprecated syntax"></span> ==
{{Unreferenced section|date=August 2025}}
 
* [[Backtick]] style command substitutions: {{Code| `...`| bash}} is deprecated in favor of
Line 3,221 ⟶ 3,163:
| url = https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html
| url-status = live
| website = tldp.org[[Linux Documentation Project]]
}}</ref>
 
Line 3,320 ⟶ 3,262:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASHPID
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,335 ⟶ 3,277:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fARGC
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,350 ⟶ 3,292:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fARGV
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,365 ⟶ 3,307:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fLINENO
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,380 ⟶ 3,322:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fREMATCH
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,395 ⟶ 3,337:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fSOURCE
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,410 ⟶ 3,352:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-BASH_005fXTRACEFD
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,425 ⟶ 3,367:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-EPOCHREALTIME
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,440 ⟶ 3,382:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-FUNCNAME
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,455 ⟶ 3,397:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-LINENO
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,470 ⟶ 3,412:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-PIPESTATUS
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,485 ⟶ 3,427:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-PPID
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,500 ⟶ 3,442:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-PS4
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
| {{dunno}}
Line 3,550 ⟶ 3,492:
| title = GNU Bash Manual, 3.5.3: Shell Parameter Expansion
| url = https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}
|
Line 3,575 ⟶ 3,517:
| title = Bash Reference Manual: 3.4.2: Special Parameters
| url = https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref><ref>
{{Cite web
Line 3,589 ⟶ 3,531:
| title = GNU Bash Manual, 4.3.1: The Set Builtin
| url = https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}
|
Line 3,611 ⟶ 3,553:
| title = Bourne Shell Builtins (Bash Reference Manual)
| url = https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html#index-trap
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref>
*** POSIX does specify certain uses of the {{mono|trap}} builtin: ...
Line 3,623 ⟶ 3,565:
| title = Bash Reference Manual: 5.2: Bash Variables
| url = https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref><ref>
{{Cite web
Line 3,639 ⟶ 3,581:
| title = The Shopt Builtin (Bash Reference Manual)
| url = https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
| website = gnu[[Free Software Foundation, Inc.org]]
}}</ref><ref name =case.edu_bash1/>
** Shell Builtin {{mono|trap}}:<ref name =gnu.org_trap/><ref name =case.edu_bash1/>
Line 3,857 ⟶ 3,799:
 
=== Timeline ===
<!-- consider moving to dedicated 'Timeline of Bash' article -->
Significant events in Bash history are listed below:
 
{| class = "wikitable sortable collapsible collapsed"
! Date
! Event
Line 3,898 ⟶ 3,842:
| url = https://www.gnu.org/gnu/thegnuproject.html
| url-status = live
| website = gnu[[Free Software Foundation, Inc.org]]
 
}}
Line 4,155 ⟶ 4,099:
Bash became the default shell on Apple's operating systems (i.e., MacOS) starting with OS X 10.3 Panther.<ref>[https://www.google.com/books/edition/Essential_Mac_OS_X_Panther_Server_Admini/zrI-U0KWj3cC?hl=en&gbpv=1&dq=bash&pg=PA189&printsec=frontcover Essential Mac OS S Panther Server Administration, pg 189]
</ref><ref>
{{Cite webbook
| access-date = 8 August 2025
| archive-date = 2 March 2021
Line 4,173 ⟶ 4,117:
| url = https://books.google.com/books?id=dwIRERUpQPEC&q=bash+most+popular+unix+shell&pg=PA6
| url-status = live
| website = google.com
}}
</ref>
Line 4,444 ⟶ 4,387:
| url = https://ftp.gnu.org/gnu/bash
| url-status = live
| website = gnu[[Free Software Foundation, Inc.org]]
}}
</ref>
 
=== Unix shells ===
{{div col|colwidth=24em}}
 
* [[Almquist shell | Almquist shell (ash)]]
* [[Bourne shell | Bourne shell (sh)]]
Line 4,479 ⟶ 4,422:
* yash – Yet Another Shell, aims "to be the most POSIX-compliant shell in the world"; available on Arch.
* [[Z shell | Z shell (zsh)]]
{{Cleardiv col end}}
 
<!-- This subsection added from https://ru.wikipedia.org/wiki/Bash on 6 Aug 2025 -->
 
=== Graphical interface to scripts ===
There are many programs that allow you to create a graphical interface for shell scripts.