Bash (Unix shell): Difference between revisions

Content deleted Content added
Definitions: Move the paragraph on delineating lines from character streams down from subsection Execution to subsection Syntax
Tag: Reverted
Observability: Move paragraph on Thompson comments into subsection xtrace; delete subsection Comments; moving it to section Definitions
Tag: Reverted
Line 1,457:
[x] Description and visual example of xtrace
[x] How to enable and disable xtrace
[x] Thompson-style comments visible in xtrace
[x] xtrace re POSIX
-->
Line 1,476 ⟶ 1,477:
$
</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,521 ⟶ 1,499:
 
:<syntaxhighlight lang="console">
$ # Define foo=bar
$ foo=bar # An inline hashtag comment occurs on the same line as a command
$ set -x
$ # A regular comment (no output)
$ : "${foo}"
+ : bar
$
</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>
 
=== Exit codes ===
Line 1,540 ⟶ 1,527:
[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| $? }}.