<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wikicyber.org/index.php?action=history&amp;feed=atom&amp;title=Draft%3AAdvanced_Bash</id>
	<title>Draft:Advanced Bash - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wikicyber.org/index.php?action=history&amp;feed=atom&amp;title=Draft%3AAdvanced_Bash"/>
	<link rel="alternate" type="text/html" href="https://wikicyber.org/index.php?title=Draft:Advanced_Bash&amp;action=history"/>
	<updated>2026-09-24T04:43:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wikicyber.org/index.php?title=Draft:Advanced_Bash&amp;diff=163&amp;oldid=prev</id>
		<title>MigrationBot: Backfill (v3.0 review queue): added to the review queue</title>
		<link rel="alternate" type="text/html" href="https://wikicyber.org/index.php?title=Draft:Advanced_Bash&amp;diff=163&amp;oldid=prev"/>
		<updated>2026-09-22T05:42:34Z</updated>

		<summary type="html">&lt;p&gt;Backfill (v3.0 review queue): added to the review queue&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw-interface=&quot;&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 05:42, 22 September 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l97&quot;&gt;Line 97:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 97:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Linux Fundamentals|021]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Linux Fundamentals|021]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Migrated from cypat.guide]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:Migrated from cypat.guide]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Pending review]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wikicyber:diff:1.41:old-83:rev-163:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>MigrationBot</name></author>
	</entry>
	<entry>
		<id>https://wikicyber.org/index.php?title=Draft:Advanced_Bash&amp;diff=83&amp;oldid=prev</id>
		<title>MigrationBot: Import from cypat.guide: docs/linux/linux_fundamentals/advanced_bash.md</title>
		<link rel="alternate" type="text/html" href="https://wikicyber.org/index.php?title=Draft:Advanced_Bash&amp;diff=83&amp;oldid=prev"/>
		<updated>2026-09-18T17:06:10Z</updated>

		<summary type="html">&lt;p&gt;Import from cypat.guide: docs/linux/linux_fundamentals/advanced_bash.md&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Submit}}&lt;br /&gt;
&amp;lt;!-- Migrated from https://cypat.guide/docs/linux/linux_fundamentals/advanced_bash (source: docs/linux/linux_fundamentals/advanced_bash.md) --&amp;gt;&lt;br /&gt;
Author(s): Matthias Lee (ml2322) &amp;lt;br /&amp;gt; Last Updated: 07-07-2025&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;mw-collapsible mw-collapsed wikitable&amp;quot; style=&amp;quot;width:100%&amp;quot;&lt;br /&gt;
! Recommended Prerequisites (click to expand)&lt;br /&gt;
|-&lt;br /&gt;
|&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Introductory and intermediate bash&amp;lt;/li&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
In addition to what we&amp;#039;ve already learned, bash has some very useful advanced functions.&lt;br /&gt;
&lt;br /&gt;
=== Exit codes ===&lt;br /&gt;
&lt;br /&gt;
After a command completes in bash, the &amp;lt;code&amp;gt;?&amp;lt;/code&amp;gt; variable will be set to its exit code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;user@system:/home/user$ ls&lt;br /&gt;
Desktop&lt;br /&gt;
Documents&lt;br /&gt;
Downloads&lt;br /&gt;
user@system:/home/user$ echo $?&lt;br /&gt;
0&lt;br /&gt;
user@system:/home/user$ ls Images&lt;br /&gt;
ls: cannot access &amp;#039;images&amp;#039;: No such file or directory&lt;br /&gt;
user@system:/home/user$ echo $?&lt;br /&gt;
2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Interpolation ===&lt;br /&gt;
&lt;br /&gt;
Just like Bash can substitute variable names for there values, it can also replace commands with what happens when you run them with interpolation. If you wrap a command in &amp;lt;code&amp;gt;$()&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;``&amp;lt;/code&amp;gt;, it will be executed, and replaced with its result. For example, if &amp;lt;code&amp;gt;a_command&amp;lt;/code&amp;gt; would return &amp;lt;code&amp;gt;Desktop&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ls $(a_command)&amp;lt;/code&amp;gt; will actually execute as &amp;lt;code&amp;gt;ls Desktop&amp;lt;/code&amp;gt;, and will therefore list everything in the desktop. &amp;lt;code&amp;gt;$()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;``&amp;lt;/code&amp;gt; are equivalent in function, but the former is preferred in most cases, as it is cleaner and can nest.&lt;br /&gt;
&lt;br /&gt;
=== Arrays ===&lt;br /&gt;
&lt;br /&gt;
Bash can hold not just text, but arrays, in its variables. You define an array in parenthesis like this: &amp;lt;code&amp;gt;array=(one two three)&amp;lt;/code&amp;gt;. To access elements in an array, we use the &amp;lt;code&amp;gt;${}&amp;lt;/code&amp;gt; syntax from earlier like this: &amp;lt;code&amp;gt;${array[0]}&amp;lt;/code&amp;gt;. Like any regular language, 0 is the start, and -1 is the end. &amp;lt;code&amp;gt;${array[@]}&amp;lt;/code&amp;gt; returns every element in the array. You can also use slices like this: &amp;lt;code&amp;gt;${array[@]:0:3}&amp;lt;/code&amp;gt;, which will get elements 0, 1, and 2. To take slices from the end, you can do &amp;lt;code&amp;gt;${array[@]: -2}&amp;lt;/code&amp;gt;, which will get the last two elements. NOTE: You &amp;#039;&amp;#039;do&amp;#039;&amp;#039; need to include the space after the colon for this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;user@system:/home/user$ array=(one two three four)&lt;br /&gt;
user@system:/home/user$ echo ${array[0]}&lt;br /&gt;
one&lt;br /&gt;
user@system:/home/user$ echo ${array[2]}&lt;br /&gt;
three&lt;br /&gt;
user@system:/home/user$ echo ${array[-1]}&lt;br /&gt;
four&lt;br /&gt;
user@system:/home/user$ echo ${array[@]}&lt;br /&gt;
one two three four&lt;br /&gt;
user@system:/home/user$ echo ${array[@]:0:3}&lt;br /&gt;
one two three&lt;br /&gt;
user@system:/home/user$ echo ${array[@]: -3}&lt;br /&gt;
two three four&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
== Bash for scripting ==&lt;br /&gt;
&lt;br /&gt;
Bash, as previously mentioned, can be used for scripts too, so it includes all the control features you would expect of a scripting language.&lt;br /&gt;
&lt;br /&gt;
=== IF statements ===&lt;br /&gt;
&lt;br /&gt;
Bash IF statements use the following syntax:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;if &amp;lt;commands&amp;gt;; then&lt;br /&gt;
    ...&lt;br /&gt;
elif &amp;lt;commands&amp;gt;; then&lt;br /&gt;
    ...&lt;br /&gt;
else&lt;br /&gt;
    ...&lt;br /&gt;
fi&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
IF statements are decided based on the commands you put in &amp;lt;code&amp;gt;&amp;amp;lt;commands&amp;amp;gt;&amp;lt;/code&amp;gt; (you can use command joining). It will execute if the commands succeed (exit code 0). However, to do more basic operations like comparing strings in an if statement, you can use &amp;lt;code&amp;gt;&amp;amp;#91;&amp;amp;#91; &amp;amp;#93;&amp;amp;#93;&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;(( ))&amp;lt;/code&amp;gt; for math. Technically, &amp;lt;code&amp;gt;&amp;amp;#91;&amp;amp;#91;&amp;lt;/code&amp;gt; is a command, but we can treat it as just part of the syntax. Some basic ways to use this are as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;if [[ &amp;quot;str a&amp;quot; == &amp;quot;str b&amp;quot; ]]; then&lt;br /&gt;
(runs if the two strings are equal)&lt;br /&gt;
&lt;br /&gt;
if [[ &amp;quot;str a&amp;quot; != &amp;quot;str b&amp;quot; ]]; then&lt;br /&gt;
(runs if the two strings are not euqal)&lt;br /&gt;
&lt;br /&gt;
if (( 1 == 2 )); then&lt;br /&gt;
(runs if the two operands are equal)&lt;br /&gt;
&lt;br /&gt;
if (( 1 &amp;gt; 2 )); then&lt;br /&gt;
(runs if 1 &amp;gt; 2)&lt;br /&gt;
&lt;br /&gt;
if (( $a &amp;lt;= $b )); then&lt;br /&gt;
(runs if a &amp;lt;= b)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
NOTE: The strings can include variables, or even include just a variable, and the numbers can be substituted for variables that only contain numbers.&lt;br /&gt;
&lt;br /&gt;
=== For loops ===&lt;br /&gt;
&lt;br /&gt;
You can do a for loop in bash as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;for i in &amp;quot;${array[@]}&amp;quot;; do&lt;br /&gt;
    echo &amp;quot;$i&amp;quot;&lt;br /&gt;
done&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
This will iterate over every element in &amp;lt;code&amp;gt;array&amp;lt;/code&amp;gt;. You can use slicing here to only get some of the array.&lt;br /&gt;
&lt;br /&gt;
====== Further Reading ======&lt;br /&gt;
&lt;br /&gt;
* https://linuxhandbook.com/bash/&lt;br /&gt;
* https://tldp.org/LDP/abs/html&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux Fundamentals|021]]&lt;br /&gt;
[[Category:Migrated from cypat.guide]]&lt;/div&gt;</summary>
		<author><name>MigrationBot</name></author>
	</entry>
</feed>