Content deleted Content added
Blush30720 (talk | contribs) Undid revision 1307855327 by OceanLoop Reverting second disruptive edit. |
m fix quot; repair |
||
(14 intermediate revisions by 6 users not shown) | |||
Line 1:
{{Short description
{{multiple issues|
{{how-to|date=August 2025}}
{{More refs|date=August 2025}}
{{
}}
{{Use dmy dates|date=March 2014}}
{{Infobox software
Line 241 ⟶ 239:
=== ASCII, strings and numbers <span class="anchor" id="ASCII"></span> <span class="anchor" id="strings"></span> <span class="anchor" id="numbers"></span> ===
<!-- Important concepts:
[x] Characters
[x] Human/computer communitcation
Line 249 ⟶ 247:
[ ] Information
-->
{{Blockquote
| The input language to the shell shall be first recognized at the character level.<ref>
Line 329 ⟶ 319:
</syntaxhighlight>
<!-- Important concepts:
[x] String
[x] Filenames
-->
Any series of characters is called a "[[String (computer science) |string]]," or sometimes a "[[string literal]]."
In Unix-like operating systems, all characters, printable and non-printing, except for a few such as the [[null character]] and forward slash {{char|/}}, can be used in naming [[Filenames |files]].
Line 346 ⟶ 340:
</ref>
<!-- Important concepts:
[x] Zero-based numbering
[]
-->
In everyday life, people usually begin counting some group of items from the number one: 1, 2, 3 apples.
In computer science it is customary to do as the computers do and begin counting the first item from the number zero: 0, 1, 2 oranges, for a total of 3 oranges.
Line 407 ⟶ 405:
=== CLI and GUI <span class="anchor" id="CLI and GUI"></span> ===
{{Main
Line 422 ⟶ 414:
}}
<!-- Important concepts:
[x] Origin of CLI paradigm
[x] Origin of terminal emulators
[x] GUI
-->
Long after the first Analytical Engine, in the mid-1960's one of the primary ways for humans and computers to interact in real time was at a keyboard with a [[teleprinter]]: only display of textual characters was possible.<ref>
{{Cite web
Line 452 ⟶ 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 504 ⟶ 499:
| website = hypexr.org
}}</ref>
=== 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 530 ⟶ 505:
[] stream of characters
[] delineate full commandlines (newline, semi-colon)
[] division into commands and parts of commands (optargs)
[] uses metacharacters
-->
<syntaxhighlight lang = text>
"Tokens"
\_ "Blanks"
\_ "Operators" (Ops)
\_ "Control Ops"
\_ "Redirection Ops"
\_ "Words"
\_ "Reserved Words"
\_ "Names"
</syntaxhighlight>
{{Blockquote
Line 548 ⟶ 531:
}}
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:)
Line 669 ⟶ 621:
<!-- Important concepts:
[]
-->
"Expansion" is a crucial concept in Unix-like shells. See [[String interpolation]].
Line 703 ⟶ 653:
[x] Arrays
-->
For data structures Bash offers variables and arrays, and though there are numerous kinds of each of these available, the data structures are relatively simple compared to other languages like [[C (programming language) |C]] or [[Java (programming language) |Java]].<ref>{{Cite web
| access-date = 15 August 2025
Line 714 ⟶ 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 843 ⟶ 793:
=== Processes <span class="anchor" id="Processes"></span> ===
{{Main
| Process (computing)
| Attribute (computing)
}}
<!-- Important concepts:
Line 852 ⟶ 807:
[x] Working directory
-->
Each [[operating system]] (OS) has at its core a program called the [[Kernel (operating system) |kernel]] which runs commands.<ref name = Brit_control-unit>
{{Cite web
Line 899 ⟶ 848:
=== Files and permissions <span class="anchor" id="Files and permissions"></span><span class="anchor" id="Files"></span><span class="anchor" id="Permissions"></span> ===
{{Main
| File system
| Unix file types
| File-system permissions
}}
<!-- This subsection is messy -->
Line 908 ⟶ 863:
[?] umask
-->
In Unix-like operating systems, all objects locatable on the [[file system]] are considered to be "files."<ref name = tldp_3.1.1>
{{Cite web
Line 957 ⟶ 905:
=== Paths <span class="anchor" id="Paths"></span> ===
{{Main |Path (computing)
| Hierarchical file system
}}
<!-- Important concepts:
Line 963 ⟶ 915:
[x] File anchor: './'
-->
In Unix-like OS's, files, hardlinks, device nodes, etc., (i.e., "files") are sorted into [[Directory (computing) |directories]] that form a hierarchical file structure which is nested in a "parent" and "child" manner.
The base of the hierarchy is called the "root directory" which is denoted by one forward slash: {{char|/}}.
Line 993 ⟶ 940:
=== Execution <span class="anchor" id="Execution"></span> ===
{{Main
| Execution (computing)
}}
<!-- Important concepts:
[x] Execution / to execute a command
[x] An executable
[x] Bash reads one line at a time
[x] Line continuation
[x] Command position
[ ] A single logical construct is parsed as a single unit
-->
"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 {{code|;}} 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's usually possible to keep typing and the command will wrap around.
To extend a command beyond a newline onto an additional line, it's necessary that the final character of the first line be an unescaped backslash, {{code|\}}, 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.
:<syntaxhighlight lang="console">
$ foo=aa bar=bb quux=cc zork=dd; set -o xtrace
$ : "${foo}"; : "${bar}"
+ : aa
+ : bb
$ : "${quux}" \
> : "${zork}"
+ : cc : dd
$
</syntaxhighlight>
The first word of a commandline is known as the "command position."
Line 1,198 ⟶ 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 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/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,483 ⟶ 1,456:
[x] Description and visual example of xtrace
[x] How to enable and disable xtrace
[x] xtrace re POSIX
-->
Line 1,503 ⟶ 1,475:
$
</syntaxhighlight>
The {{Mono| xtrace}} shell setting is specified by POSIX.
See also {{section link||Debugging}}.
=== The {{mono| verbose}} option ===
<!-- Important concepts:
[x] Saying something about Verbose mode
-->
The verbose option prints strings to the terminal as they are read, and before any expansions are performed. Rarely used.<ref>See {{Code| set -v| bash}} in the documentation.</ref>
=== Comments ===
<!-- Important concepts:
[x] Comments
[x] Inline comments
[x] Observability of 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}}.
Comments denoted with a colon character, {{char|:}}, originated with the [[Thompson shell]].<ref>
Line 1,525 ⟶ 1,520:
:<syntaxhighlight lang="console">
$ # Define foo
$ foo=bar # An inline hashtag comment occurs on the same line as a command
$ set -x
$ # A regular comment (no output)
$ : "${foo}"
+ : bar
$
</syntaxhighlight>
=== Exit codes ===
Line 1,553 ⟶ 1,539:
[x] Lack of standardization
-->
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:' {{Code| $? }}.
Line 2,172 ⟶ 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.]]
}}</ref>
Line 2,351 ⟶ 2,335:
-->
{{Blockquote
| ITERATION: Sometimes programs are repeated indefinitely or until a specific outcome is reached. Each execution of the instructions is an
{{Cite web
| access-date = 15 August 2025
|