Bash (Unix shell): Difference between revisions

Content deleted Content added
Undid revision 1307857444 by OceanLoop Reverting disruptive edit from yesterday. Work on the prose is in-process.
Tags: Undo Reverted
m fix quot; repair
 
(15 intermediate revisions by 6 users not shown)
Line 1:
{{Short description |GNU replacement for the Bourne shell}}
{{multiple issues|
<!-- -->
{{More refshow-to|date=August 2025}}
<!-- Do not give aspirin ⇒ The WHO advises against the use of aspirin -->
{{More refs|date=August 2025}}
<!-- -->
{{In useOver-quotation| date =August 2025-08-12| section = entire article}}
}}
<!--{{Under construction|date=2025-08-12|nosection=yes}}-->
{{How-to|date=January 2019}}
{{More refs|date=August 2025}}
{{Use dmy dates|date=March 2014}}
{{Infobox software
Line 451 ⟶ 449:
[x] Terminal emulator as separate from shell
-->
 
This functionality is provided by a program called [[GNU 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.
 
Line 503 ⟶ 499:
| website = hypexr.org
}}</ref>
 
=== Comments ===
 
<!-- Important concepts:
[x] Comments
[x] Inline comments
-->
 
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 hashtag character: {{char|#}}.
Any text to the right of the hashtag to the end of the line will be ignored.
Inline comments are allowed, but hashtag comments will not print during debugging. See also: {{section link||xtrace}}.
 
:<syntaxhighlight lang="console">
$ echo '<foo>' # An inline hashtag comment occurs on the same line as a command
<foo>
$ # A regular comment (no output)
$
</syntaxhighlight>
 
=== Syntax <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> ===
Line 687 ⟶ 663:
All data is stored in memory as a string.
 
'''Syntax common among data structures in Bash:'''
Beginnning 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.
Line 1,185 ⟶ 1,162:
[ ] scripts execute the contents of a file in a subshell
-->
 
With the {{code| source}}, or synonymous {{code| .}} command, Bash reads and executes shell commands from a file by name.<ref name="gnuBuiltin">{{cite web |title=4.1 Bourne Shell Builtins |url=https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html |website=4 Shell Builtin Commands |publisher=[[Free Software Foundation, Inc.]] |access-date=August 25, 2025}}</ref>
With the {{code| source}}, or synonymous {{code| .}} command, Bash reads and executes shell commands from any text file by name.<ref>
{{Cite web
| 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/TheBourne-SetShell-BuiltinBuiltins.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 2,171 ⟶ 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
/software/bash/manual/html_node/The-Set-Builtin.html
| website = [[Free Software Foundation, Inc.]]
}}</ref>
Line 2,350 ⟶ 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