<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Danish Khan</title>
    <description>The latest articles on Forem by Danish Khan (@deekay99).</description>
    <link>https://forem.com/deekay99</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1485856%2F93ed4d4a-9dfd-4a15-b6d5-8027d4691f25.png</url>
      <title>Forem: Danish Khan</title>
      <link>https://forem.com/deekay99</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/deekay99"/>
    <language>en</language>
    <item>
      <title>🚀 Python for SRE/DevOps: Building SDKs + Jenkins Automations</title>
      <dc:creator>Danish Khan</dc:creator>
      <pubDate>Wed, 25 Mar 2026 11:28:20 +0000</pubDate>
      <link>https://forem.com/deekay99/python-for-sredevops-building-sdks-jenkins-automations-34f2</link>
      <guid>https://forem.com/deekay99/python-for-sredevops-building-sdks-jenkins-automations-34f2</guid>
      <description>&lt;p&gt;A practical, step-by-step roadmap to learn how to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Build reusable Python SDKs&lt;/li&gt;
&lt;li&gt;Package and publish them&lt;/li&gt;
&lt;li&gt;Use them in Jenkins pipelines&lt;/li&gt;
&lt;li&gt;Automate real-world SRE workflows (alerts, infra, APIs)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 Big Picture Architecture
&lt;/h2&gt;

&lt;p&gt;Python Script → Internal SDK → HTTP API → External System →  Jenkins (cron/scheduled execution)&lt;/p&gt;

&lt;p&gt;You are learning how to build &lt;strong&gt;internal automation platforms&lt;/strong&gt;, not just scripts.&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Phase 1: Python Foundations (Automation-Focused)
&lt;/h2&gt;

&lt;h2&gt;
  
  
  What to Learn
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Functions, modules, imports&lt;/li&gt;
&lt;li&gt;Virtual environments (venv)&lt;/li&gt;
&lt;li&gt;JSON &amp;amp; YAML handling&lt;/li&gt;
&lt;li&gt;Exception handling&lt;/li&gt;
&lt;li&gt;Basic classes &amp;amp; objects&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;📘 Automate the Boring Stuff with Python&lt;/strong&gt; 👉&lt;a href="https://automatetheboringstuff.com/" rel="noopener noreferrer"&gt;https://automatetheboringstuff.com/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;📘 Python Crash Course&lt;/strong&gt;  👉 &lt;a href="https://ehmatthes.github.io/pcc/" rel="noopener noreferrer"&gt;https://ehmatthes.github.io/pcc/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;🌐 Real Python (Core Concepts)&lt;/strong&gt;  👉 &lt;a href="https://realpython.com/" rel="noopener noreferrer"&gt;https://realpython.com/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🌐 Phase 2: APIs First (Before SDKs)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What to Learn
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;HTTP methods: &lt;em&gt;GET&lt;/em&gt;, &lt;em&gt;POST&lt;/em&gt;, &lt;em&gt;DELETE&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Headers &amp;amp; authentication&lt;/li&gt;
&lt;li&gt;JSON request/response&lt;/li&gt;
&lt;li&gt;Status codes&lt;/li&gt;
&lt;li&gt;Timeouts &amp;amp; Retries&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;🌐 MDN HTTP Guide&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/HTTP&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📦 Python requests Library&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://docs.python-requests.org/" rel="noopener noreferrer"&gt;https://docs.python-requests.org/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;⚡ FastAPI Tutorial (API understanding)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://fastapi.tiangolo.com/" rel="noopener noreferrer"&gt;https://fastapi.tiangolo.com/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🧪 Practice
&lt;/h3&gt;

&lt;p&gt;Write a script that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Calls an API&lt;/li&gt;
&lt;li&gt;Fetches data&lt;/li&gt;
&lt;li&gt;Sends POST request&lt;/li&gt;
&lt;li&gt;Deletes a resource&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📦 Phase 3: Python Packaging (VERY IMPORTANT)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What to Learn
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;setup.py vs pyproject.toml&lt;/li&gt;
&lt;li&gt;pip install mechanics&lt;/li&gt;
&lt;li&gt;wheel format&lt;/li&gt;
&lt;li&gt;package versioning&lt;/li&gt;
&lt;li&gt;private package repositories&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📘 Python Packaging User Guide&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://packaging.python.org/" rel="noopener noreferrer"&gt;https://packaging.python.org/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📦 setuptools Documentation&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://setuptools.pypa.io/" rel="noopener noreferrer"&gt;https://setuptools.pypa.io/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📦 Poetry Documentation&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://python-poetry.org/docs/" rel="noopener noreferrer"&gt;https://python-poetry.org/docs/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📦 Twine (Publishing Packages)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://twine.readthedocs.io/" rel="noopener noreferrer"&gt;https://twine.readthedocs.io/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;🌐 Real Python Packaging Guide&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://realpython.com/pypi-publish-python-package/" rel="noopener noreferrer"&gt;https://realpython.com/pypi-publish-python-package/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🧪 Practice
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create a Python package&lt;/li&gt;
&lt;li&gt;Build it (&lt;code&gt;python -m build&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Install locally using &lt;code&gt;pip&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Import it in another project&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🏗️ Phase 4: Building SDK-Style Code
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What to Learn
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Class-based design&lt;/li&gt;
&lt;li&gt;Client abstraction&lt;/li&gt;
&lt;li&gt;BaseClient pattern&lt;/li&gt;
&lt;li&gt;Error handling&lt;/li&gt;
&lt;li&gt;Code structure&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Typical SDK Structure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_sdk/
├── client.py
├── base_client.py
├── models.py
├── exceptions.py
├── utils.py
└── init.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📘 Clean Code in Python&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://www.packtpub.com/product/clean-code-in-python/9781788835831" rel="noopener noreferrer"&gt;https://www.packtpub.com/product/clean-code-in-python/9781788835831&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📘 Cosmic Python (Architecture)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://www.cosmicpython.com/" rel="noopener noreferrer"&gt;https://www.cosmicpython.com/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📘 Fluent Python (Advanced)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://www.oreilly.com/library/view/fluent-python/9781492056348/" rel="noopener noreferrer"&gt;https://www.oreilly.com/library/view/fluent-python/9781492056348/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🧪 Practice
&lt;/h3&gt;

&lt;p&gt;Build a client like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MonitoringClient&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create_event&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_events&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delete_event&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ⚙️ Phase 5: Jenkins + Python Integration
&lt;/h2&gt;

&lt;h2&gt;
  
  
  What to Learn
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Jenkins pipelines (Jenkinsfile)&lt;/li&gt;
&lt;li&gt;Running Python scripts&lt;/li&gt;
&lt;li&gt;Environment variables&lt;/li&gt;
&lt;li&gt;Cron scheduling&lt;/li&gt;
&lt;li&gt;Dependency installation (pip in pipeline)&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📘 Jenkins Pipeline Docs&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://www.jenkins.io/doc/book/pipeline/" rel="noopener noreferrer"&gt;https://www.jenkins.io/doc/book/pipeline/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;🎓 KodeKloud Jenkins Course&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://kodekloud.com/courses/jenkins/" rel="noopener noreferrer"&gt;https://kodekloud.com/courses/jenkins/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🧪 Practice
&lt;/h3&gt;

&lt;p&gt;Create pipeline:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install package via pip&lt;/li&gt;
&lt;li&gt;Run Python script&lt;/li&gt;
&lt;li&gt;Capture output&lt;/li&gt;
&lt;li&gt;Trigger via cron&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧪 Phase 6: Testing (CRITICAL for SRE)
&lt;/h2&gt;

&lt;h2&gt;
  
  
  What to Learn
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;pytest basics&lt;/li&gt;
&lt;li&gt;mocking APIs&lt;/li&gt;
&lt;li&gt;testing client methods&lt;/li&gt;
&lt;li&gt;safe execution patterns&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📦 pytest Documentation&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://docs.pytest.org/" rel="noopener noreferrer"&gt;https://docs.pytest.org/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📘 Python Testing with pytest&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://pragprog.com/titles/bopytest/python-testing-with-pytest/" rel="noopener noreferrer"&gt;https://pragprog.com/titles/bopytest/python-testing-with-pytest/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;🌐 Real Python Testing Guide&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://realpython.com/pytest-python-testing/" rel="noopener noreferrer"&gt;https://realpython.com/pytest-python-testing/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⚡ Phase 7: Async Python (Advanced)
&lt;/h2&gt;

&lt;h2&gt;
  
  
  What to Learn
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;async / await&lt;/li&gt;
&lt;li&gt;event loop&lt;/li&gt;
&lt;li&gt;concurrent API calls&lt;/li&gt;
&lt;li&gt;async HTTP clients&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Resources
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;🌐 Real Python Async Guide&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://realpython.com/async-io-python/" rel="noopener noreferrer"&gt;https://realpython.com/async-io-python/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📘 Python asyncio Docs&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://docs.python.org/3/library/asyncio.html" rel="noopener noreferrer"&gt;https://docs.python.org/3/library/asyncio.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;📦 HTTPX (async HTTP client)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://www.python-httpx.org/" rel="noopener noreferrer"&gt;https://www.python-httpx.org/&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧱 Real-World Pattern You Are Learning
&lt;/h2&gt;

&lt;p&gt;This pattern is used everywhere in platform engineering:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Internal Python SDK&lt;/li&gt;
&lt;li&gt;Published as package&lt;/li&gt;
&lt;li&gt;Stored in private repo&lt;/li&gt;
&lt;li&gt;Installed in pipelines&lt;/li&gt;
&lt;li&gt;Used for automation tasks&lt;/li&gt;
&lt;li&gt;Triggered via cron&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔥 Mini Project (Must Do)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Project: Monitoring Automation SDK
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Structure
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;monitoring-sdk/
├── monitoring_client/
│ ├── client.py
│ ├── base_client.py
│ ├── models.py
│ ├── exceptions.py
│ └── utils.py
├── scripts/
│ ├── create_event.py
│ ├── cleanup_event.py
├── tests/
├── pyproject.toml
└── Jenkinsfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create event (POST)&lt;/li&gt;
&lt;li&gt;List events (GET)&lt;/li&gt;
&lt;li&gt;Delete event (DELETE)&lt;/li&gt;
&lt;li&gt;Package SDK&lt;/li&gt;
&lt;li&gt;Install via pip&lt;/li&gt;
&lt;li&gt;Run via Jenkins&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📅 7-Day Fast-Track Plan
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Day 1
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Learn venv, pip&lt;/li&gt;
&lt;li&gt;Run Python scripts&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Day 2
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Learn requests&lt;/li&gt;
&lt;li&gt;Call an API&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Day 3
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Write API client class&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Day 4
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Convert to package&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Day 5
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Install package locally&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Day 6
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Write automation script&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Day 7
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Run via Jenkins pipeline&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 Final Insight
&lt;/h2&gt;

&lt;p&gt;You are not learning Python.&lt;br&gt;
You are learning to build:&lt;br&gt;
👉 &lt;strong&gt;Internal Developer Platforms&lt;/strong&gt;&lt;br&gt;
👉 &lt;strong&gt;Automation of Toolings,API and Systems&lt;/strong&gt;&lt;br&gt;
👉 &lt;strong&gt;Reusable Engineering Tools used internally and are created using Python&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is exactly what strong SREs/DevOps and Platform Engineers do.&lt;br&gt;
This is how in future you can even contribute to &lt;em&gt;Open Source Software&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Next Step : Coming Soon (WIP)
&lt;/h2&gt;

&lt;p&gt;👉 A &lt;strong&gt;complete working project template (SDK + Jenkins + API mock)&lt;/strong&gt;.&lt;br&gt;
👉 Tailored to this above workflow. &lt;/p&gt;

&lt;p&gt;Just share it further on LinkedIn, Substack 👍&lt;/p&gt;

</description>
      <category>sre</category>
      <category>devops</category>
      <category>python</category>
      <category>jenkins</category>
    </item>
    <item>
      <title>Bash Scripting for Non-Coders</title>
      <dc:creator>Danish Khan</dc:creator>
      <pubDate>Sat, 06 Dec 2025 15:03:27 +0000</pubDate>
      <link>https://forem.com/deekay99/bash-scripting-for-non-coders-1dgm</link>
      <guid>https://forem.com/deekay99/bash-scripting-for-non-coders-1dgm</guid>
      <description>&lt;h2&gt;
  
  
  A Practical, No-Fear Guide to Understanding the Shell
&lt;/h2&gt;

&lt;p&gt;Learning Bash can feel intimidating if you don’t come from a programming background. Terminals look cryptic, commands seem unforgiving, and even simple tasks appear wrapped in strange symbols like |, &amp;gt;, and &amp;amp;&amp;amp;.&lt;br&gt;
But here’s the truth:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You don’t need to be a coder to write useful Bash scripts.&lt;/li&gt;
&lt;li&gt;You just need to understand how Bash works and how you can think in bash.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This guide is written specifically for non-coders, beginners, and anyone who feels “new” to the command line.&lt;br&gt;
Instead of overwhelming you with theory, we’ll build intuition step-by-step using simple explanations, real-world analogies, and tiny hands-on examples. By the end, you’ll have the confidence to automate tasks, avoid mistakes, and write scripts that actually work.&lt;/p&gt;

&lt;p&gt;Whether you’re a DevOps engineer, a sysadmin, a student, or someone simply curious about the terminal—this guide will help you move from:&lt;/p&gt;

&lt;p&gt;❌ “I don’t understand Bash…” to&lt;br&gt;
✅ “I can write scripts that solve real problems.”&lt;/p&gt;

&lt;p&gt;Let’s begin your journey into Bash—no coding background required.&lt;/p&gt;


&lt;h3&gt;
  
  
  Piping &amp;amp; Re-direction
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Re-direction in Bash
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Stream&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Content&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;Standard Input (stdin)&lt;/td&gt;
&lt;td&gt;keyboard or other input&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Standard Output (stdout)&lt;/td&gt;
&lt;td&gt;Regular Output&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Standard Error (stderr)&lt;/td&gt;
&lt;td&gt;Output marked as 'error'&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Re-direction in file
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symbol&lt;/th&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Output redirection (truncate)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Output redirection (append)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Input redirection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Here documentation&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  Commands and Built-In
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;echo ends a line in a new line&lt;/li&gt;
&lt;li&gt;Likewise is printf, but it leaves the exit on the same line.&lt;/li&gt;
&lt;li&gt;Check if something is &lt;code&gt;command&lt;/code&gt; or a builtin
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="nt"&gt;-V&lt;/span&gt; &lt;span class="nb"&gt;echo
echo &lt;/span&gt;is a shell &lt;span class="nb"&gt;builtin
&lt;/span&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="nt"&gt;-V&lt;/span&gt; &lt;span class="nb"&gt;df 
df &lt;/span&gt;is /usr/bin/df
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Built-Ins take precedents over commands. Bash will run a builtin if it has one, even if there's a command of the same name available on the system. But specific builtins can be disabled in a session with &lt;code&gt;enable -n&lt;/code&gt; and the name of the builtin, allowing the command version to run instead. &lt;/li&gt;
&lt;li&gt;For eg. We can disable echo builtin via below command.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;enable&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="nb"&gt;echo 
&lt;/span&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="nt"&gt;-V&lt;/span&gt; &lt;span class="nb"&gt;echo
echo &lt;/span&gt;is /usr/bin/echo
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;enable&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt;
&lt;span class="nb"&gt;enable&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;&lt;p&gt;As shown above enable -n by itself shows builtins that are disabled. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can re-enable the builtin with enable and the name of the builtin.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;enable echo
&lt;/span&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="nt"&gt;-V&lt;/span&gt; &lt;span class="nb"&gt;echo
echo &lt;/span&gt;is a shell &lt;span class="nb"&gt;builtin
&lt;/span&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Another important distinction to make here is that builtins use a different documentation system than the regular &lt;code&gt;man&lt;/code&gt; pages. &lt;/li&gt;
&lt;li&gt;There's a builtin called &lt;code&gt;help&lt;/code&gt; that shows supporting information about builtins. &lt;/li&gt;
&lt;li&gt;For example, we can write &lt;code&gt;help echo&lt;/code&gt;, and find out what we can do with the echo builtin.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;help echo
echo&lt;/span&gt;: &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-neE&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;arg ...]
    Write arguments to the standard output.

    Display the ARGs, separated by a single space character and followed by a
    newline, on the standard output.

    Options:
      &lt;span class="nt"&gt;-n&lt;/span&gt;    &lt;span class="k"&gt;do &lt;/span&gt;not append a newline
      &lt;span class="nt"&gt;-e&lt;/span&gt;    &lt;span class="nb"&gt;enable &lt;/span&gt;interpretation of the following backslash escapes
      &lt;span class="nt"&gt;-E&lt;/span&gt;    explicitly suppress interpretation of backslash escapes

    &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt;&lt;span class="s1"&gt;' interprets the following backslash-escaped characters:
      \a    alert (bell)
      \b    backspace
      \c    suppress further output
      \e    escape character
      \E    escape character
      \f    form feed
      \n    new line
      \r    carriage return
      \t    horizontal tab
      \v    vertical tab
      \\    backslash
      \0nnn the character whose ASCII code is NNN (octal).  NNN can be
            0 to 3 octal digits
      \xHH  the eight-bit character whose value is HH (hexadecimal).  HH
            can be one or two hex digits
      \uHHHH    the Unicode character whose value is the hexadecimal value HHHH.
            HHHH can be one to four hex digits.
      \UHHHHHHHH the Unicode character whose value is the hexadecimal value
            HHHHHHHH. HHHHHHHH can be one to eight hex digits.

    Exit Status:
    Returns success unless a write error occurs.
danish@danish-Ubuntu:~$ 
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Using the &lt;code&gt;help&lt;/code&gt; built-In, we can display the names of all the other builtins.&lt;/li&gt;
&lt;li&gt;Here's the list of the builtins that Bash provides.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;help
&lt;/span&gt;GNU bash, version 5.0.17&lt;span class="o"&gt;(&lt;/span&gt;1&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nt"&gt;-release&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;x86_64-pc-linux-gnu&lt;span class="o"&gt;)&lt;/span&gt;
These shell commands are defined internally.  Type &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;help&lt;/span&gt;&lt;span class="s1"&gt;' to see this list.
Type `help name'&lt;/span&gt; to find out more about the &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="sb"&gt;`&lt;/span&gt;name&lt;span class="s1"&gt;'.
Use `info bash'&lt;/span&gt; to find out more about the shell &lt;span class="k"&gt;in &lt;/span&gt;general.
Use &lt;span class="sb"&gt;`&lt;/span&gt;man &lt;span class="nt"&gt;-k&lt;/span&gt;&lt;span class="s1"&gt;' or `info'&lt;/span&gt; to find out more about commands not &lt;span class="k"&gt;in &lt;/span&gt;this list.

A star &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; next to a name means that the &lt;span class="nb"&gt;command &lt;/span&gt;is disabled.

 job_spec &lt;span class="o"&gt;[&lt;/span&gt;&amp;amp;]                                                                                         &lt;span class="nb"&gt;history&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-c&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-d&lt;/span&gt; offset] &lt;span class="o"&gt;[&lt;/span&gt;n] or &lt;span class="nb"&gt;history&lt;/span&gt; &lt;span class="nt"&gt;-anrw&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;filename] or &lt;span class="nb"&gt;history&lt;/span&gt; &lt;span class="nt"&gt;-ps&lt;/span&gt; arg &lt;span class="o"&gt;[&lt;/span&gt;arg...]
 &lt;span class="o"&gt;((&lt;/span&gt; expression &lt;span class="o"&gt;))&lt;/span&gt;                                                                                     &lt;span class="k"&gt;if &lt;/span&gt;COMMANDS&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then &lt;/span&gt;COMMANDS&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="k"&gt;elif &lt;/span&gt;COMMANDS&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then &lt;/span&gt;COMMANDS&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;... &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="k"&gt;else &lt;/span&gt;COMMANDS&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="k"&gt;fi&lt;/span&gt;
 &lt;span class="nb"&gt;.&lt;/span&gt; filename &lt;span class="o"&gt;[&lt;/span&gt;arguments]                                                                               &lt;span class="nb"&gt;jobs&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-lnprs&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;jobspec ...] or &lt;span class="nb"&gt;jobs&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;args]
 :                                                                                                    &lt;span class="nb"&gt;kill&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-s&lt;/span&gt; sigspec | &lt;span class="nt"&gt;-n&lt;/span&gt; signum | &lt;span class="nt"&gt;-sigspec&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; pid | jobspec ... or &lt;span class="nb"&gt;kill&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;sigspec]
 &lt;span class="o"&gt;[&lt;/span&gt; arg... &lt;span class="o"&gt;]&lt;/span&gt;                                                                                           &lt;span class="nb"&gt;let &lt;/span&gt;arg &lt;span class="o"&gt;[&lt;/span&gt;arg ...]
 &lt;span class="o"&gt;[[&lt;/span&gt; expression &lt;span class="o"&gt;]]&lt;/span&gt;                                                                                     &lt;span class="nb"&gt;local&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;option] name[&lt;span class="o"&gt;=&lt;/span&gt;value] ...
 &lt;span class="nb"&gt;alias&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-p&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;name[&lt;span class="o"&gt;=&lt;/span&gt;value] ... &lt;span class="o"&gt;]&lt;/span&gt;                                                                       &lt;span class="nb"&gt;logout&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;n]
 &lt;span class="nb"&gt;bg&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;job_spec ...]                                                                                    &lt;span class="nb"&gt;mapfile&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-d&lt;/span&gt; delim] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-n&lt;/span&gt; count] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-O&lt;/span&gt; origin] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-s&lt;/span&gt; count] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-t&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-u&lt;/span&gt; fd] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-C&lt;/span&gt; callback] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-c&lt;/span&gt; quantum] &lt;span class="o"&gt;[&lt;/span&gt;arr&amp;gt;
 &lt;span class="nb"&gt;bind&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-lpsvPSVX&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-m&lt;/span&gt; keymap] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-f&lt;/span&gt; filename] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-q&lt;/span&gt; name] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-u&lt;/span&gt; name] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-r&lt;/span&gt; keyseq] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-x&lt;/span&gt; keyseq:shell-comman&amp;gt;  &lt;span class="nb"&gt;popd&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-n&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;+N | &lt;span class="nt"&gt;-N&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
 &lt;span class="nb"&gt;break&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;n]                                                                                            &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-v&lt;/span&gt; var] format &lt;span class="o"&gt;[&lt;/span&gt;arguments]
 &lt;span class="nb"&gt;builtin&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;shell-builtin &lt;span class="o"&gt;[&lt;/span&gt;arg ...]]                                                                    &lt;span class="nb"&gt;pushd&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-n&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;+N | &lt;span class="nt"&gt;-N&lt;/span&gt; | &lt;span class="nb"&gt;dir&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
 &lt;span class="nb"&gt;caller&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;expr&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;                                                                                        &lt;span class="nb"&gt;pwd&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-LP&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
 &lt;span class="k"&gt;case&lt;/span&gt; WORD &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;PATTERN &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; PATTERN]...&lt;span class="p"&gt;)&lt;/span&gt; COMMANDS &lt;span class="p"&gt;;;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;... &lt;span class="k"&gt;esac&lt;/span&gt;                                           &lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-ers&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-a&lt;/span&gt; array] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-d&lt;/span&gt; delim] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-i&lt;/span&gt; text] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-n&lt;/span&gt; nchars] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-N&lt;/span&gt; nchars] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-p&lt;/span&gt; prompt] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nb"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-u&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-L&lt;/span&gt;|[-P &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-e&lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;-@]] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;dir&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;                                                                         readarray &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-d&lt;/span&gt; delim] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-n&lt;/span&gt; count] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-O&lt;/span&gt; origin] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-s&lt;/span&gt; count] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-t&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-u&lt;/span&gt; fd] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-C&lt;/span&gt; callback] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-c&lt;/span&gt; quantum] &lt;span class="o"&gt;[&lt;/span&gt;a&amp;gt;
 &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-pVv&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;arg ...]                                                                     &lt;span class="nb"&gt;readonly&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-aAf&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;name[&lt;span class="o"&gt;=&lt;/span&gt;value] ...] or &lt;span class="nb"&gt;readonly&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt;
 &lt;span class="nb"&gt;compgen&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-abcdefgjksuv&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-o&lt;/span&gt; option] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-A&lt;/span&gt; action] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-G&lt;/span&gt; globpat] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-W&lt;/span&gt; wordlist]  &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-F&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-C&lt;/span&gt; &lt;span class="nb"&gt;comm&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;n]
 &lt;span class="nb"&gt;complete&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-abcdefgjksuv&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-pr&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-DEI&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-o&lt;/span&gt; option] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-A&lt;/span&gt; action] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-G&lt;/span&gt; globpat] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-W&lt;/span&gt; wordlist]  &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-F&lt;/span&gt; func&amp;gt;  &lt;span class="k"&gt;select &lt;/span&gt;NAME &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;in &lt;/span&gt;WORDS ... &lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;COMMANDS&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done
 &lt;/span&gt;compopt &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-o&lt;/span&gt;|+o option] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-DEI&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;name ...]                                                             &lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-abefhkmnptuvxBCHP&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-o&lt;/span&gt; option-name] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;arg ...]
 &lt;span class="k"&gt;continue&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;n]                                                                                         &lt;span class="nb"&gt;shift&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;n]
 coproc &lt;span class="o"&gt;[&lt;/span&gt;NAME] &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;redirections]                                                                 &lt;span class="nb"&gt;shopt&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-pqsu&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-o&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;optname ...]
 &lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-aAfFgilnrtux&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-p&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;name[&lt;span class="o"&gt;=&lt;/span&gt;value] ...]                                                      &lt;span class="nb"&gt;source &lt;/span&gt;filename &lt;span class="o"&gt;[&lt;/span&gt;arguments]
 &lt;span class="nb"&gt;dirs&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-clpv&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;+N] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-N&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;                                                                               &lt;span class="nb"&gt;suspend&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-f&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
 &lt;span class="nb"&gt;disown&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-h&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-ar&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;jobspec ... | pid ...]                                                            &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;expr&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-neE&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;arg ...]                                                                                &lt;span class="nb"&gt;time&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-p&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; pipeline
 &lt;span class="nb"&gt;enable&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-a&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-dnps&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-f&lt;/span&gt; filename] &lt;span class="o"&gt;[&lt;/span&gt;name ...]                                                         &lt;span class="nb"&gt;times
 eval&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;arg ...]                                                                                       &lt;span class="nb"&gt;trap&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-lp&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt;arg] signal_spec ...]
 &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-cl&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-a&lt;/span&gt; name] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;arguments ...]] &lt;span class="o"&gt;[&lt;/span&gt;redirection ...]                                     &lt;span class="nb"&gt;true
 exit&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;n]                                                                                             &lt;span class="nb"&gt;type&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-afptP&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; name &lt;span class="o"&gt;[&lt;/span&gt;name ...]
 &lt;span class="nb"&gt;export&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-fn&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;name[&lt;span class="o"&gt;=&lt;/span&gt;value] ...] or &lt;span class="nb"&gt;export&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt;                                                         &lt;span class="nb"&gt;typeset&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-aAfFgilnrtux&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-p&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; name[&lt;span class="o"&gt;=&lt;/span&gt;value] ...
 &lt;span class="nb"&gt;false                                                                                                ulimit&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-SHabcdefiklmnpqrstuvxPT&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;limit]
 &lt;span class="nb"&gt;fc&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-e&lt;/span&gt; ename] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-lnr&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;first] &lt;span class="o"&gt;[&lt;/span&gt;last] or &lt;span class="nb"&gt;fc&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;pat&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;rep] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;                                     &lt;span class="nb"&gt;umask&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-p&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-S&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;mode]
 &lt;span class="nb"&gt;fg&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;job_spec]                                                                                        &lt;span class="nb"&gt;unalias&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-a&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; name &lt;span class="o"&gt;[&lt;/span&gt;name ...]
 &lt;span class="k"&gt;for &lt;/span&gt;NAME &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="k"&gt;in &lt;/span&gt;WORDS ... &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;COMMANDS&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done                                                         &lt;/span&gt;&lt;span class="nb"&gt;unset&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-f&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-v&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-n&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;name ...]
 &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;((&lt;/span&gt; exp1&lt;span class="p"&gt;;&lt;/span&gt; exp2&lt;span class="p"&gt;;&lt;/span&gt; exp3 &lt;span class="o"&gt;))&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;COMMANDS&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done                                                        until &lt;/span&gt;COMMANDS&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;COMMANDS&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done
 function &lt;/span&gt;name &lt;span class="o"&gt;{&lt;/span&gt; COMMANDS &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt; or name &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; COMMANDS &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;                                               variables - Names and meanings of some shell variables
 &lt;span class="nb"&gt;getopts &lt;/span&gt;optstring name &lt;span class="o"&gt;[&lt;/span&gt;arg]                                                                         &lt;span class="nb"&gt;wait&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-fn&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt; ...]
 &lt;span class="nb"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-lr&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-p&lt;/span&gt; pathname] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-dt&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;name ...]                                                            &lt;span class="k"&gt;while &lt;/span&gt;COMMANDS&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;COMMANDS&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done
 &lt;/span&gt;&lt;span class="nb"&gt;help&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-dms&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;pattern ...]                                                                            &lt;span class="o"&gt;{&lt;/span&gt; COMMANDS &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;We can find &lt;code&gt;echo&lt;/code&gt; and &lt;code&gt;enable&lt;/code&gt;, which we saw earlier and so on. To explore more about these, you can write &lt;code&gt;help&lt;/code&gt; and any of these names. &lt;/li&gt;
&lt;li&gt;Bash builtins are useful at the command line and also in scripts, but it's important to know the difference between builtins and commands.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Bash Expansions &amp;amp; Substitutions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When we're working with Bash, either at the command line or in the script, we'll often need to use values that we don't know. &lt;/li&gt;
&lt;li&gt;Things like a path to the user's home folder, a piece of user provided information, or the result of a calculation that's based on something we can't foresee. &lt;/li&gt;
&lt;li&gt;Bash provides us a way to represent these values using expansions and substitutions. &lt;/li&gt;
&lt;li&gt;Both of these are interpreted when they run and replace themselves with a value or a set of values. &lt;/li&gt;
&lt;li&gt;Because they're very important to scripting, lets explore them.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Representation&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;~&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Tilde expansion&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;{...}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Brace expansion&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;${...}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Parameter expansion&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$(...)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Command substitution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;$((...))&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Airthmetic expansion&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h4&gt;
  
  
  Tilde Expansion &lt;code&gt;~&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;In Bash, the tilde character represents the value of the user's $HOME variable. And it's used in paths to represent the current user's $HOME directory. We can see that here with echo and the tilde character.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; ~
/home/danish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Tilde expansion is useful when we're scripting, because if we want to do something in a user's $HOME directory, which is a pretty important place, we can do that without knowing their username. &lt;/li&gt;
&lt;li&gt;Tilde just represents whatever the current user's $HOME directory is set to. So, here on my system, that's &lt;code&gt;/home/danish&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;But on your system, the same tilde represents home and whatever is your username.&lt;/li&gt;
&lt;li&gt;Another useful tilde expansion trick is that the tilde followed by a dash or minus represents a Bash variable called &lt;code&gt;OLDPWD&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Which is the directory that you were just in, if you've recently changed directories. You can use this to work with other directories in the directory stack. Which is useful for command line use, but not as much for scripting.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;
/home/danish
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; ~-
/sys/fs/cgroup/freezer/mycgroup
danish@danish-Ubuntu:~&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For info take a look at the tilde expansion section of the Bash Man pages.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Brace Expansion &lt;code&gt;{...}&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Another useful type of expansion is called brace expansion. This is written with braces around an expression, and it lets us substitute in items from a list of values separated by commas, or ranges of numbers or letters in a given pattern, separated by two dots or periods. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Brace expansion is often used when we need to keep part of a path the same, but replace a little piece of it. &lt;/li&gt;
&lt;li&gt;For example, if we wanted to create a file inside each of three different directory trees where only part of the path needs to change each time, or we could use it to provide a set of values to use in the same part of a string more generally. The other form of brace expansion, which creates a sequence of numbers or letters, is often used when working with sequential items.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; /tmp/&lt;span class="o"&gt;{&lt;/span&gt;one,two,three&lt;span class="o"&gt;}&lt;/span&gt;/file.txt
/tmp/one/file.txt /tmp/two/file.txt /tmp/three/file.txt
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;c&lt;span class="o"&gt;{&lt;/span&gt;a,s,d&lt;span class="o"&gt;}&lt;/span&gt;t
&lt;span class="nb"&gt;cat &lt;/span&gt;cst cdt
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; /tmp/&lt;span class="o"&gt;{&lt;/span&gt;1..3&lt;span class="o"&gt;}&lt;/span&gt;/file.txt
/tmp/1/file.txt /tmp/2/file.txt /tmp/3/file.txt
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For example, We can write something like echo {1..10} to get the numbers one through 10, or echo {10..1} to get the same numbers but in reverse order.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;1..10&lt;span class="o"&gt;}&lt;/span&gt;
1 2 3 4 5 6 7 8 9 10
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;10..1&lt;span class="o"&gt;}&lt;/span&gt; 
10 9 8 7 6 5 4 3 2 1
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;I can generate letters, too. I'll write echo {a..z} and echo {Z..A}. With either kind of sequence.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;a..z&lt;span class="o"&gt;}&lt;/span&gt;
a b c d e f g h i j k l m n o p q r s t u v w x y z
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;A..Z&lt;span class="o"&gt;}&lt;/span&gt; 
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can add an interval, too. For example, echo {1..50..2} will return every second number between 1 and 50.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;1..50..2&lt;span class="o"&gt;}&lt;/span&gt; 
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Below command will return every letter between a and z leaving the second letter after each, like it left &lt;code&gt;b&lt;/code&gt;, then &lt;code&gt;d&lt;/code&gt; then &lt;code&gt;f&lt;/code&gt; and so on.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;a..l..2&lt;span class="o"&gt;}&lt;/span&gt;
a c e g i k
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Brace expansion can also be used to work with set lists of things. For example, I can write echo, tree,flower,bee, and that returns what we might expect. As we saw before, we can combine it with other expansions.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;tree,flower,bee&lt;span class="o"&gt;}&lt;/span&gt;
tree flower bee
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;tree,flower,bee&lt;span class="o"&gt;}&lt;/span&gt;_&lt;span class="o"&gt;{&lt;/span&gt;1..3&lt;span class="o"&gt;}&lt;/span&gt;
tree_1 tree_2 tree_3 flower_1 flower_2 flower_3 bee_1 bee_2 bee_3
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We'll often find this used for directories or when working with files that have a predefined naming scheme, and brace expansion can be used as kind of a shorthand when working with commands, too.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Parameter expansion &lt;code&gt;${...}&lt;/code&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Parameter expansion lets us recall stored values and transform them in various ways. This is usually represented by a dollar sign and a set of braces. Though, sometimes we'll see it without the braces. &lt;/li&gt;
&lt;li&gt;The most straightforward use of parameter expansion is setting a value and then retrieving it, as we'll do when we make use of variables and scripting later on. &lt;/li&gt;
&lt;li&gt;When we're using parameter expansion in this way, we'll set a parameter equal to a value, and then use the dollar sign with the name of that parameter to retrieve the value later. &lt;/li&gt;
&lt;li&gt;Parameter expansion also often features braces. Those are used to make it clear what parameter is being used and to keep the shell from getting confused about nearby words or characters. &lt;/li&gt;
&lt;li&gt;They're also used for extracting substrings or manipulating the value of a parameter as it's being used.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"my parameter"&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;
my parameter
danish@danish-Ubuntu:~&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the string is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;m  y     p  a  r  a  m  e  t  e  r
0  1 2   3  4  5  6  7  8  9  10 11 12
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spaces count as characters too.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
my parameter
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start at index 1, extract 5 characters.&lt;br&gt;
Indexing starts at 0, so:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Index 0 = m&lt;/li&gt;
&lt;li&gt;Index 1 = y&lt;/li&gt;
&lt;li&gt;Next 4 chars = par
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;:1:5&lt;span class="k"&gt;}&lt;/span&gt;
y par
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;String Replacement: ${var/pattern/replacement}&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"my parameter"&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
my parameter
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="p"&gt;/parameter/Second Entry&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
my Second Entry
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replaces ONLY the first occurrence of pattern.&lt;br&gt;
Summary:-&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Expression&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Example Output&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;${a}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Value of variable&lt;/td&gt;
&lt;td&gt;&lt;code&gt;my parameter&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;${a:start:length}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Substring extraction&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;${a:1:5}&lt;/code&gt; → &lt;code&gt;y par&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;${a/pattern/repl}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Replace first match&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;${a/parameter/x}&lt;/code&gt; → &lt;code&gt;my x&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;${a//pattern/repl}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Replace ALL matches&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;${a//a/x}&lt;/code&gt; → &lt;code&gt;my parameter&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;${a/pattern}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Delete first match&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;${a/para}&lt;/code&gt; → &lt;code&gt;meter&lt;/code&gt; (removes &lt;code&gt;para&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;${#a}&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;String length&lt;/td&gt;
&lt;td&gt;&lt;code&gt;13&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;In a script, we just use the dollar sign parameter part, usually without echo. But here in the shell, we will need to use echo to see what the value of that parameter is. &lt;/li&gt;
&lt;li&gt;Parameter expansion can also be used to manipulate the stored value when it's used, transforming it in various ways, like just using part of the value or replacing certain parts before the value is used. For example as shown above.&lt;/li&gt;
&lt;li&gt;Let's replace all of the E's with an underscore. I'll write echo &lt;code&gt;parameter//e/_&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;
my parameter
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="p"&gt;//e/_&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
my param_t_r
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Let's do the same thing with just one slash, and we can see the difference.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;
my parameter
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="p"&gt;/e/_&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
my param_ter
danish@danish-Ubuntu:~&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;We'll use braces for most parameter expansions, because if we left them off, the shell would just interpret the part after the parameter name as characters and show them instead of using them to do what we intend. &lt;/li&gt;
&lt;li&gt;For example, I'll write &lt;code&gt;echo $a:4:3&lt;/code&gt; without the braces. And here, I see the string &lt;code&gt;my parameter :4:3&lt;/code&gt;. As we'll see though, parameter expansion without the braces is common.Bash only performs substring extraction when you use &lt;code&gt;${variable:start:length}&lt;/code&gt; format.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"my parameter"&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;
my parameter
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;:2:5
my parameter:2:5
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;:2:5&lt;span class="k"&gt;}&lt;/span&gt;
para
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Command Substitution &lt;code&gt;$(...)&lt;/code&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Command substitution is a kind of special case expansion which allows us to use the output of a command within another command. &lt;/li&gt;
&lt;li&gt;This is represented by a dollar sign and a set of parentheses enclosing a command. &lt;/li&gt;
&lt;li&gt;An alternate way of writing this is to use two back ticks, but that often gets confusing. So generally, we write it with the parentheses. &lt;/li&gt;
&lt;li&gt;Bash runs the specified command in a subshell and returns the output of that into the current command. It's often used together with string manipulation tools to extract a part of a command's output, such as a path, a file size, an IP address, or so on, that needs to be handed back up to the parent command. &lt;/li&gt;
&lt;li&gt;Let's take a look at using command substitution. For example, we could use uname -r to get the release version of the kernel. And with command substitution, we could use that in an echo statement.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt;
5.15.0-91-generic
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The kernel version is &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;."&lt;/span&gt;
The kernel version is 5.15.0-91-generic.
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The GIT version is &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;git &lt;span class="nt"&gt;--version&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;."&lt;/span&gt;
The GIT version is git version 2.25.1.
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;We'll often use something like this in scripts to get the version of something the user has installed or some metrics about the system that might be relevant to how our script works. We can use longer commands within the parentheses too, including command pipelines, and you can nest command substitutions within one another in case you have a complex series of commands that depend on the results of other commands. Here, I'm using python to print out a string, and using tr to transform it to all caps. And then the result of that is being used in my echo statement.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;python &lt;span class="nt"&gt;-c&lt;/span&gt; print&lt;span class="s1"&gt;'("Hello from Python.")'&lt;/span&gt;
Hello from Python.
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Result: &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;python &lt;span class="nt"&gt;-c&lt;/span&gt; print&lt;span class="s1"&gt;'("Hello from Python.")'&lt;/span&gt; |tr &lt;span class="o"&gt;[&lt;/span&gt;a-z] &lt;span class="o"&gt;[&lt;/span&gt;A-Z]&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
Result: HELLO FROM PYTHON.
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;See how it's useful to capture the output of a command and use it in another command. &lt;/li&gt;
&lt;li&gt;Command substitution is often used with tools such as GREP, AWK, and CUT, and is widely used to determine whether a script has what it needs on the target system.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Arithmetic expansion &lt;code&gt;$((...))&lt;/code&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Bash can use arithmetic expansion to perform arithmetic or calculations and use the result in a command. &lt;/li&gt;
&lt;li&gt;This is represented by a dollar sign and two sets of parentheses with an arithmetic expression inside. &lt;/li&gt;
&lt;li&gt;Earlier versions of Bash also used a dollar sign with single brackets, but this is deprecated now. &lt;/li&gt;
&lt;li&gt;You may see it in older scripts though. Let's do a couple of basic calculations here. &lt;/li&gt;
&lt;li&gt;Let's take a look at two plus two, and that's four. &lt;/li&gt;
&lt;li&gt;Expansions and substitutions are really important features of Bash, and its up to the user how he/she intended to use them in scripts.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;
10
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;
2
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;9&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;
1
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Programming/Scripting in Bash
&lt;/h2&gt;

&lt;p&gt;Running a program in bash&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It can be one liners ( Series of bash commands separated via semicolon or pipes) &lt;/li&gt;
&lt;li&gt;It can be alias of a long command&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Bash Script
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Text commands that uses a series of commands&lt;/li&gt;
&lt;li&gt;Run it via &lt;code&gt;bash script.sh&lt;/code&gt;
#### Executable Bash Script&lt;/li&gt;
&lt;li&gt;Includes a shebang at the start
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;A shebang line starts with a pound or hash sign and an exclamation mark, and then the full path to whatever program should run the script. &lt;/li&gt;
&lt;li&gt;In this case, we'll use Bash but this can be anything like Python,Ruby or Perl whatever interpreted scripting language you need to make into a program. &lt;/li&gt;
&lt;li&gt;It's common to see the absolute path to Bash in a shebang line in older script like, &lt;code&gt;/bin/bash&lt;/code&gt; it's often considered a best practice to write the shebang line in a way that uses the shell's environment to locate the Bash executable. &lt;/li&gt;
&lt;li&gt;Not all systems have Bash in the same place though almost all of them do. And so instead of asking for &lt;code&gt;/bin/bash&lt;/code&gt; and not finding it in that file path, we ask the environment to give us Bash which will work wherever Bash is installed. &lt;/li&gt;
&lt;li&gt;If we leave off a shebang, the contents of the script file will be passed to the current shell on that Linux system which mostly will be Bash anyway but we don't know what shell other people are using at any given time, so it makes sense to include the shebang. &lt;/li&gt;
&lt;li&gt;Writing shebang guarantee that our Bash script is run by Bash.&lt;/li&gt;
&lt;li&gt;When creating an executable script will usually leave the file extension off, but that's entirely up to you. &lt;/li&gt;
&lt;li&gt;The second step of making an executable script is to make it executable. You'll do that with &lt;code&gt;chmod + X scriptname&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Now I can run this by typing &lt;code&gt;./scriptname&lt;/code&gt; and if I were to place this file somewhere the shell could find it somewhere in the path. I can just use the name of the script like a regular command. &lt;/li&gt;
&lt;li&gt;A Bash script runs inside of a non interactive shell, which means that many of the customizations a user might have set for their Bash environment won't be read when the script is run. Unlike when we use a regular interactive shell. &lt;/li&gt;
&lt;li&gt;This gives the script a fairly clean environment in which to run, and if we want to make any customizations or specifically override other settings we'll need to use &lt;code&gt;set&lt;/code&gt; or &lt;code&gt;shopt&lt;/code&gt; in our script to turn on or off configurations accordingly. In most cases, we don't need to do this but it's something that's available if necessary. Writing Bash scripts allows us to avoid typos, to streamline work using Bash and they allow us to distribute our Bash code to other systems that need to run it and one-liners are useful as well.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Using echo in Bash
&lt;/h3&gt;

&lt;p&gt;Various ways of using the echo is shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ myvariable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;dkvalue1
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$myvariable&lt;/span&gt; 
dkvalue1
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$myvariable&lt;/span&gt; : printing the value
dkvalue1 : printing the value
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;Now &lt;span class="nv"&gt;$myvariable&lt;/span&gt; : printing the value
Now dkvalue1 : printing the value
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The kernel is &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
The kernel is Linux danish-Ubuntu 5.15.0-91-generic &lt;span class="c"&gt;#101~20.04.1-Ubuntu SMP Thu Nov 16 14:22:28 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The kernel is &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
The kernel is 5.15.0-91-generic
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;The kernel is &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
The kernel is 5.15.0-91-generic
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;The&lt;span class="o"&gt;(&lt;/span&gt; kernel&lt;span class="o"&gt;)&lt;/span&gt; is &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
bash: syntax error near unexpected token &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'
danish@danish-Ubuntu:~$ 
danish@danish-Ubuntu:~$ echo The (kernel) is $(uname -r)
bash: syntax error near unexpected token `('&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;The &lt;span class="se"&gt;\(&lt;/span&gt;kernel&lt;span class="se"&gt;\)&lt;/span&gt; is &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
The &lt;span class="o"&gt;(&lt;/span&gt;kernel&lt;span class="o"&gt;)&lt;/span&gt; is 5.15.0-91-generic
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The kernel is &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
The kernel is 5.15.0-91-generic
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'The kernel is $(uname -r)'&lt;/span&gt;
The kernel is &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'The kernel is $(uname -r)'&lt;/span&gt;
The kernel is &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo 

&lt;/span&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &lt;span class="s2"&gt;"Disabling the Cursor for exiting to new line"&lt;/span&gt; 
Disabling the Cursor &lt;span class="k"&gt;for &lt;/span&gt;exiting to new line 
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Working with Variables in Bash
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In Bash, variables are an expression of parameter expansion.&lt;/li&gt;
&lt;li&gt;In Bash, parameters, or in this case, variables are named with alpha numeric characters, and we assign a value to that name with an equal sign followed by whatever value we want it to store. &lt;/li&gt;
&lt;li&gt;It's important to remember that there should be no space on either side of the equal sign.&lt;/li&gt;
&lt;li&gt;Variable names are case sensitive. In many cases, we can use lowercase names for our variables. Though you can use capitalized or all caps names too. &lt;/li&gt;
&lt;li&gt;Using lowercase variables helps us to distinguish our variables from environment and system variables, which are nearly always upper case. &lt;/li&gt;
&lt;li&gt;A variable could also contain a number. So to use these variables, we refer to them with a dollar sign in front of their name.&lt;/li&gt;
&lt;li&gt;Remember, this is the sort of special case parameter expansion where we don't need to use the braces, but we can if we want to, or if we need to use only part of that string value. These variables will be available in that shell session until it closes. &lt;/li&gt;
&lt;li&gt;Example of a script for the same
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="nv"&gt;myvar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Hello!"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The value of the myvar variable is: &lt;/span&gt;&lt;span class="nv"&gt;$myvar&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nv"&gt;myvar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Bonjour!"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The value of the myvar variable is: &lt;/span&gt;&lt;span class="nv"&gt;$myvar&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="nv"&gt;myname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;bob
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The value of the myname variable is: &lt;/span&gt;&lt;span class="nv"&gt;$myname&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nv"&gt;myname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Iceman"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The value of the myname variable is: &lt;/span&gt;&lt;span class="nv"&gt;$myname&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; &lt;span class="nv"&gt;lowerstring&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"This is some TEXT!"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The value of the lowerstring variable is: &lt;/span&gt;&lt;span class="nv"&gt;$lowerstring&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nv"&gt;lowerstring&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Let's CHANGE THE VALUE"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The value of the lowerstring variable is: &lt;/span&gt;&lt;span class="nv"&gt;$lowerstring&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; &lt;span class="nv"&gt;upperstring&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"This is some TEXT!"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The value of the upperstring variable is: &lt;/span&gt;&lt;span class="nv"&gt;$upperstring&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nv"&gt;lowerstring&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Let's CHANGE THE VALUE"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The value of the upperstring variable is: &lt;/span&gt;&lt;span class="nv"&gt;$upperstring&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now we make the script executable and then run the script
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;./variables_check.sh
The value of the myvar variable is: Hello!
The value of the myvar variable is: Bonjour!
The value of the myname variable is: bob
./variable-decleration_script.sh: line 9: myname: &lt;span class="nb"&gt;readonly &lt;/span&gt;variable
The value of the myname variable is: bob
The value of the lowerstring variable is: this is some text!
The value of the lowerstring variable is: &lt;span class="nb"&gt;let&lt;/span&gt;&lt;span class="s1"&gt;'s change the value
The value of the upperstring variable is: THIS IS SOME TEXT!
The value of the upperstring variable is: THIS IS SOME TEXT!
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What is happening at line 9? &lt;br&gt;
Script declares:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="nv"&gt;myname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;bob
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-r&lt;/code&gt; means:&lt;br&gt;
&lt;code&gt;myname&lt;/code&gt; becomes a readonly variable&lt;/p&gt;

&lt;p&gt;In Bash, a readonly variable cannot be changed, reassigned, or unset after its declaration.&lt;/p&gt;

&lt;p&gt;This is equivalent to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;readonly &lt;/span&gt;&lt;span class="nv"&gt;myname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;bob
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the value is permanently fixed to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bob
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Line 9 tries to REASSIGN a readonly variable.&lt;br&gt;
This triggers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;line 9: myname: &lt;span class="nb"&gt;readonly &lt;/span&gt;variable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Q: Why does Bash have readonly variables?&lt;br&gt;
Readonly variables are used to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;protect constants&lt;/li&gt;
&lt;li&gt;avoid accidental changes&lt;/li&gt;
&lt;li&gt;enforce configuration values&lt;/li&gt;
&lt;li&gt;lock down environment variables&lt;/li&gt;
&lt;li&gt;write safer scripts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;readonly &lt;/span&gt;&lt;span class="nv"&gt;APP_ENV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;production
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now nothing can override it—even if someone tries.&lt;/p&gt;

&lt;h4&gt;
  
  
  Bash &lt;code&gt;declare&lt;/code&gt; Options (Professional Cheat Sheet)
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Variable Attributes
&lt;/h5&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;What Happens&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-r&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Readonly (cannot reassign)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;declare -r name="bob"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;name&lt;/code&gt; cannot be changed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Export (becomes environment var)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;declare -x PATH&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Available to child processes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-i&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Integer (auto-coerces to number)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;declare -i n=5+7&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;n&lt;/code&gt; becomes &lt;code&gt;12&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-l&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Lowercase (auto-converts assigned values)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;declare -l var="HeLLo"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;var = hello&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-u&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Uppercase (auto-converts assigned values)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;declare -u var="HeLLo"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;var = HELLO&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h5&gt;
  
  
  Arrays
&lt;/h5&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-a&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Indexed array&lt;/td&gt;
&lt;td&gt;&lt;code&gt;declare -a arr=(a b c)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-A&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Associative array (hashmap)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;declare -A config=([env]=prod [ver]=1.0)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h5&gt;
  
  
  Function Options (Rare)
&lt;/h5&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-f&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;List function definitions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-F&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;List only function names&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h5&gt;
  
  
  Visibility / Declaration
&lt;/h5&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-p&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Print variable declaration in reusable form&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Let’s go through what matters most for real SRE Bash scripting.&lt;/p&gt;

&lt;p&gt;1️⃣ -r — Readonly&lt;/p&gt;

&lt;p&gt;Used when you want constants.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="nv"&gt;APP_ENV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;prod
&lt;span class="nv"&gt;APP_ENV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"dev"&lt;/span&gt;   &lt;span class="c"&gt;# ERROR: readonly variable&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prevents accidental overwrites.&lt;/p&gt;

&lt;p&gt;2️⃣ -i — Integer&lt;/p&gt;

&lt;p&gt;Bash will automatically evaluate arithmetic expressions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nv"&gt;num&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;5+8
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$num&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;        &lt;span class="c"&gt;# 13&lt;/span&gt;


Even &lt;span class="k"&gt;if &lt;/span&gt;you try to assign a string:

&lt;span class="nv"&gt;num&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"10+20"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$num&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;        &lt;span class="c"&gt;# 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Useful for counters, sums, CPU monitoring scripts, etc.&lt;/p&gt;

&lt;p&gt;3️⃣ -l — Lowercase auto-conversion&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; &lt;span class="nv"&gt;lower&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"HeLLo WoRLD"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$lower&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;      &lt;span class="c"&gt;# hello world&lt;/span&gt;

&lt;span class="nv"&gt;lower&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"NEW VALUE"&lt;/span&gt;  &lt;span class="c"&gt;# becomes: new value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great for normalizing user input.&lt;/p&gt;

&lt;p&gt;4️⃣ -u — Uppercase auto-conversion&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; &lt;span class="nv"&gt;upper&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"HeLLo WoRLD"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$upper&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;      &lt;span class="c"&gt;# HELLO WORLD&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good for case-insensitive comparisons.&lt;/p&gt;

&lt;p&gt;5️⃣ -x — Export variable to environment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;token&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ABC123"&lt;/span&gt;
bash &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s1"&gt;'echo $token'&lt;/span&gt;   &lt;span class="c"&gt;# available here too&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Used heavily in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CI scripts&lt;/li&gt;
&lt;li&gt;wrapper scripts&lt;/li&gt;
&lt;li&gt;Kubernetes entrypoint logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;6️⃣ -a — Indexed Array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nv"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;apple banana cherry&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[1]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;     &lt;span class="c"&gt;# banana&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;7️⃣ -A — Associative Array (HashMap)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-A&lt;/span&gt; &lt;span class="nv"&gt;config&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;
  &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;env&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;prod
  &lt;span class="o"&gt;[&lt;/span&gt;app]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"backend"&lt;/span&gt;
  &lt;span class="o"&gt;[&lt;/span&gt;port]&lt;span class="o"&gt;=&lt;/span&gt;8080
&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;config&lt;/span&gt;&lt;span class="p"&gt;[env]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;   &lt;span class="c"&gt;# prod&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;config&lt;/span&gt;&lt;span class="p"&gt;[app]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;   &lt;span class="c"&gt;# backend&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Used in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;config parsing.&lt;/li&gt;
&lt;li&gt;key-value mappings.&lt;/li&gt;
&lt;li&gt;JSON-like structures in Bash.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*One of the things that's useful about declare is that you can use &lt;code&gt;declare -p&lt;/code&gt; to see all of the variables that have been set in a current session. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;So if you're working at the command line, and don't remember what you called that one variable from a little while ago, &lt;code&gt;declare -p&lt;/code&gt; will remind you.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nv"&gt;BASH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/usr/bin/bash"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="nv"&gt;BASHOPTS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"checkwinsize:cmdhist:complete_fullquote:expand_aliases:extglob:extquote:force_fignore:globasciiranges:histappend:interactive_comments:progcomp:promptvars:sourcepath"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; BASHPID
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-A&lt;/span&gt; &lt;span class="nv"&gt;BASH_ALIASES&lt;/span&gt;&lt;span class="o"&gt;=()&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nv"&gt;BASH_ARGC&lt;/span&gt;&lt;span class="o"&gt;=([&lt;/span&gt;0]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nv"&gt;BASH_ARGV&lt;/span&gt;&lt;span class="o"&gt;=()&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; BASH_ARGV0
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-A&lt;/span&gt; &lt;span class="nv"&gt;BASH_CMDS&lt;/span&gt;&lt;span class="o"&gt;=()&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; BASH_COMMAND
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nv"&gt;BASH_COMPLETION_VERSINFO&lt;/span&gt;&lt;span class="o"&gt;=([&lt;/span&gt;0]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"2"&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;1]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"10"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nv"&gt;BASH_LINENO&lt;/span&gt;&lt;span class="o"&gt;=()&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-ar&lt;/span&gt; &lt;span class="nv"&gt;BASH_REMATCH&lt;/span&gt;&lt;span class="o"&gt;=()&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nv"&gt;BASH_SOURCE&lt;/span&gt;&lt;span class="o"&gt;=()&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; BASH_SUBSHELL
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-ar&lt;/span&gt; &lt;span class="nv"&gt;BASH_VERSINFO&lt;/span&gt;&lt;span class="o"&gt;=([&lt;/span&gt;0]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"5"&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;1]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"0"&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;2]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"17"&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;3]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"1"&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;4]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"release"&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;5]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"x86_64-pc-linux-gnu"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nv"&gt;BASH_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"5.0.17(1)-release"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;COLORTERM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"truecolor"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nv"&gt;COLUMNS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"203"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nv"&gt;COMP_WORDBREAKS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"    
&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;'&amp;gt;&amp;lt;=;|&amp;amp;(:"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;DBUS_SESSION_BUS_ADDRESS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"unix:path=/run/user/1000/bus"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;DESKTOP_SESSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ubuntu"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nv"&gt;DIRSTACK&lt;/span&gt;&lt;span class="o"&gt;=()&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;DISPLAY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;":1"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; EPOCHREALTIME
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; EPOCHSECONDS
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-ir&lt;/span&gt; &lt;span class="nv"&gt;EUID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"1000"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; FUNCNAME
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;GDMSESSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ubuntu"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;GJS_DEBUG_OUTPUT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"stderr"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;GJS_DEBUG_TOPICS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"JS ERROR;JS LOG"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;GNOME_DESKTOP_SESSION_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"this-is-deprecated"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;GNOME_SHELL_SESSION_MODE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ubuntu"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;GNOME_TERMINAL_SCREEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/org/gnome/Terminal/screen/a9a1eca8_cb8a_4d39_9fff_b62f623d8f59"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;GNOME_TERMINAL_SERVICE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;":1.102"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;GPG_AGENT_INFO&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/run/user/1000/gnupg/S.gpg-agent:0:1"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nv"&gt;GROUPS&lt;/span&gt;&lt;span class="o"&gt;=()&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;GTK_MODULES&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gail:atk-bridge"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; HISTCMD
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nv"&gt;HISTCONTROL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ignoreboth"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nv"&gt;HISTFILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/home/danish/.bash_history"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nv"&gt;HISTFILESIZE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"2000"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nv"&gt;HISTSIZE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"1000"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;HOME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/home/danish"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nv"&gt;HOSTNAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"danish-Ubuntu"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nv"&gt;HOSTTYPE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"x86_64"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nv"&gt;IFS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"    
"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;IM_CONFIG_PHASE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"1"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;INVOCATION_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"a31e8df6411e421289f2185137ec2b39"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;JOURNAL_STREAM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"8:49873"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;LANG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"en_IN"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;LANGUAGE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"en_IN:en"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;LESSCLOSE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/usr/bin/lesspipe %s %s"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;LESSOPEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"| /usr/bin/lesspipe %s"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; LINENO
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nv"&gt;LINES&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"53"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-x&lt;/span&gt; &lt;span class="nv"&gt;LOGNAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"danish"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;There's a lot of variables we didn't explicitly set in here, and these are from the environment. We can use these environment variables in our scripts when we need to get a particular piece of information about the end user system. &lt;/li&gt;
&lt;li&gt;Variables are an important part of batch scripting, and unless you need to apply an attribute to a variable, you can skip using declare, and just define a variable the shorter way. &lt;/li&gt;
&lt;li&gt;But for more strict scenarios, keep declare in mind. It can help you avoid certain kinds of bugs that would otherwise be tricky to work through.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;declare&lt;/code&gt; when you need to set specific attributes for a variable, such as making it an array or read-only. &lt;/li&gt;
&lt;li&gt;For regular variable assignments, especially when the type is straightforward, you can simply assign values without using declare. &lt;/li&gt;
&lt;li&gt;This keeps your scripts cleaner and more readable for simple cases.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Working with Numbers in Bash
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When we work with numbers in Bash we have two tools at our disposal, arithmetic expansion &lt;code&gt;$((...))&lt;/code&gt; or older representation &lt;code&gt;$[...]&lt;/code&gt; and arithmetic evaluation &lt;code&gt;((...))&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;Arithmetic expansion lets us use literal numbers or variables and perform mathematical operations on them. Giving us a result we can display or assign to a variable. &lt;/li&gt;
&lt;li&gt;Arithmetic evaluation makes changes to the value of an existing variable. &lt;/li&gt;
&lt;li&gt;Bash supports six basic arithmetic operators:-&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Addition&lt;/td&gt;
&lt;td&gt;&lt;code&gt;+&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Subtraction&lt;/td&gt;
&lt;td&gt;&lt;code&gt;-&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multiplication&lt;/td&gt;
&lt;td&gt;&lt;code&gt;*&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Division&lt;/td&gt;
&lt;td&gt;&lt;code&gt;/&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Modulo&lt;/td&gt;
&lt;td&gt;&lt;code&gt;%&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exponentiation&lt;/td&gt;
&lt;td&gt;&lt;code&gt;**&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;And it's important to point out Bash can only do calculations with integers. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Arithmetic Expansion &lt;code&gt;$((...))&lt;/code&gt; examples given below:-&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;
8
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;
3
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;
6
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="m"&gt;8&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;
2
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;
&lt;span class="nt"&gt;-6&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Arithmetic evaluation is done in double parentheses but without a leading dollar sign it can change the value of the variable involved. &lt;/li&gt;
&lt;li&gt;As you can see in below exapmple Airthmatic evaluation doesn't show any output, instead we can check it's exit code.&lt;/li&gt;
&lt;li&gt;Arithmetic Evaluation &lt;code&gt;((...))&lt;/code&gt; examples given below, in this it shows how to change the value of a numeric variable
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;&lt;span class="nv"&gt;$a&lt;/span&gt;+&lt;span class="o"&gt;=&lt;/span&gt;5&lt;span class="o"&gt;))&lt;/span&gt;
bash: &lt;span class="o"&gt;((&lt;/span&gt;: 10+&lt;span class="o"&gt;=&lt;/span&gt;5: attempted assignment to non-variable &lt;span class="o"&gt;(&lt;/span&gt;error token is &lt;span class="s2"&gt;"+=5"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;a+&lt;span class="o"&gt;=&lt;/span&gt;5&lt;span class="o"&gt;))&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt;
0
danish@danish-Ubuntu:~&lt;span class="err"&gt;$&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;
15
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can add space inside the parentheses to make the expression easier to read.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="m"&gt;6&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt; 
&lt;span class="nt"&gt;-134&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Below shows that &lt;code&gt;a&lt;/code&gt; should be set equal to itself plus three.&lt;/li&gt;
&lt;li&gt;Then increment by &lt;code&gt;1&lt;/code&gt; by &lt;code&gt;++&lt;/code&gt;, then echoing it to check the updated value.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;a+&lt;span class="o"&gt;=&lt;/span&gt;3&lt;span class="o"&gt;))&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;
6
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;a++&lt;span class="o"&gt;))&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;
7
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;a++&lt;span class="o"&gt;))&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;
8
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;a--&lt;span class="o"&gt;))&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;
7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can't increment seven and then have it stored back in the variable that got expanded because the reference to the variable is gone.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;&lt;span class="nv"&gt;$a&lt;/span&gt;++&lt;span class="o"&gt;))&lt;/span&gt;
bash: &lt;span class="o"&gt;((&lt;/span&gt;: 7++: syntax error: operand expected &lt;span class="o"&gt;(&lt;/span&gt;error token is &lt;span class="s2"&gt;"+"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Instead, without using the dollar sign we tell Bash to increment whatever is in that variable without returning us the value first. We can also use combination assignments in this way to reassign the value of the variable within the expression. This provides us a shorthand way of changing the value of a numeric variable, shorter than saying A equals A plus two.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;((&lt;/span&gt;a++&lt;span class="o"&gt;))&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;
8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Using these short hands can help us reduce typos and the need to type out the variable name twice. But it also protects us from a problem that can easily occur when working with numbers in Bash. &lt;/li&gt;
&lt;li&gt;If I take a value &lt;code&gt;z=10&lt;/code&gt; and try to add to it using what looks like a pretty normal way of doing that as shown below:-
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ z&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$z&lt;/span&gt;
10
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$z&lt;/span&gt;+5
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$y&lt;/span&gt;
10+5
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The shell's happy to do that operation but we get a result that I might not expect i.e. &lt;code&gt;y = 10+5&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Issue is --&amp;gt; &lt;code&gt;Bash&lt;/code&gt; is treating this variable as a string rather than a number, so it put the characters plus&lt;code&gt;(+)&lt;/code&gt; and &lt;code&gt;5&lt;/code&gt; at the end of it instead of adding two to the number. &lt;/li&gt;
&lt;li&gt;In addition to using arithmetic evaluation to work with numbers safely, we can prevent Bash from treating numbers like strings by declaring variables we'll use for numbers as integers. &lt;/li&gt;
&lt;li&gt;Resolution --&amp;gt; We will declare the variable &lt;code&gt;z=10&lt;/code&gt; and we can treat this variable just like we did the other one but now if we wanted to add to it or to work with it Bash treats it like a number instead of a string. &lt;/li&gt;
&lt;li&gt;So while it's possible to define numeric variables the same way we do with string variables it's a better idea to use &lt;code&gt;declared -i value&lt;/code&gt; on variables you know we'll be integers:-
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;8
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$a&lt;/span&gt;+2
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$a&lt;/span&gt;
8+2
&lt;span class="c"&gt;### Problem discussed above&lt;/span&gt;
&lt;span class="c"&gt;### Solution given below&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$b&lt;/span&gt;+3
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$b&lt;/span&gt;
6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The limitation of Bash only being able to work with integers is something we'll run up against in the real world pretty quickly. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For example, if we tried to make this calculation one divided by three the result I get back is zero, not 0.3333 and so on. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And obviously that decimal part would be pretty important in a lot of situations. One third is not zero, but Bash says it is because the integer part, the whole number of the result is zero. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So to do anything that requires more precision anything that needs a floating point or a decimal to be involved we'll need to use tools other than Bash. A few common commands can do calculations including bc short for basic calculator and awk. Both bc and awk are pre-installed on many Linux distributions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let's take a very quick look at how to use bc with Bash.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;
0
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nv"&gt;d&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ e&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"scale=3; &lt;/span&gt;&lt;span class="nv"&gt;$c&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;$d&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | bc&lt;span class="si"&gt;)&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$e&lt;/span&gt;
.333
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It's important to remember that this response &lt;code&gt;0.333&lt;/code&gt; is treated as text by Bash not as a number, it's just the characters period. &lt;code&gt;0.333&lt;/code&gt;, not the numeric value, one third. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Addtional information a variable that might come hanndy. That is RANDOM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;RANDOM variable returns, a pseudo random integer between zero &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;32767&lt;/code&gt;. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can write echo, dollar sign, RANDOM (all in caps), and see the output it geneates.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$RANDOM&lt;/span&gt;
8190
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;$RANDOM&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;
9
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nv"&gt;$RANDOM&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Comparing Values with &lt;code&gt;test&lt;/code&gt; or &lt;code&gt;[ ... ]&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In scripts it's common to need to compare things and test values. Bash has a built-in called Test, which is also represented by single brackets. &lt;code&gt;[ ... ]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;This built-in works in the same way as the test command which is part of the GNU coreutils, the set of tools that are available on many Linux distributions. &lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test is widely compatible across shells and it's worth taking a moment to look at the help for the test built-in. There are a variety of operations that Test can well, test.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let's ask Bash whether my home directory is a directory.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; ~ &lt;span class="o"&gt;]&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt;
0
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;help test
test&lt;/span&gt;: &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;expr&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
    Evaluate conditional expression.

    Exits with a status of 0 &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; or 1 &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; depending on
    the evaluation of EXPR.  Expressions may be unary or binary.  Unary
    expressions are often used to examine the status of a file.  There
    are string operators and numeric comparison operators as well.

    The behavior of &lt;span class="nb"&gt;test &lt;/span&gt;depends on the number of arguments.  Read the
    bash manual page &lt;span class="k"&gt;for &lt;/span&gt;the &lt;span class="nb"&gt;complete &lt;/span&gt;specification.

    File operators:

      &lt;span class="nt"&gt;-a&lt;/span&gt; FILE        True &lt;span class="k"&gt;if &lt;/span&gt;file exists.
      &lt;span class="nt"&gt;-b&lt;/span&gt; FILE        True &lt;span class="k"&gt;if &lt;/span&gt;file is block special.
      &lt;span class="nt"&gt;-c&lt;/span&gt; FILE        True &lt;span class="k"&gt;if &lt;/span&gt;file is character special.
      &lt;span class="nt"&gt;-d&lt;/span&gt; FILE        True &lt;span class="k"&gt;if &lt;/span&gt;file is a directory.
      &lt;span class="nt"&gt;-e&lt;/span&gt; FILE        True &lt;span class="k"&gt;if &lt;/span&gt;file exists.
      &lt;span class="nt"&gt;-f&lt;/span&gt; FILE        True &lt;span class="k"&gt;if &lt;/span&gt;file exists and is a regular file.
      &lt;span class="nt"&gt;-g&lt;/span&gt; FILE        True &lt;span class="k"&gt;if &lt;/span&gt;file is set-group-id.
      &lt;span class="nt"&gt;-h&lt;/span&gt; FILE        True &lt;span class="k"&gt;if &lt;/span&gt;file is a symbolic link.
      &lt;span class="nt"&gt;-L&lt;/span&gt; FILE        True &lt;span class="k"&gt;if &lt;/span&gt;file is a symbolic link.
      &lt;span class="nt"&gt;-k&lt;/span&gt; FILE        True &lt;span class="k"&gt;if &lt;/span&gt;file has its &lt;span class="sb"&gt;`&lt;/span&gt;sticky&lt;span class="s1"&gt;' bit set.
      -p FILE        True if file is a named pipe.
      -r FILE        True if file is readable by you.
      -s FILE        True if file exists and is not empty.
      -S FILE        True if file is a socket.
      -t FD          True if FD is opened on a terminal.
      -u FILE        True if the file is set-user-id.
      -w FILE        True if the file is writable by you.
      -x FILE        True if the file is executable by you.
      -O FILE        True if the file is effectively owned by you.
      -G FILE        True if the file is effectively owned by your group.
      -N FILE        True if the file has been modified since it was last read.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;When we run a comparison or test, the result we get back is an exit or return status of a zero or a one. Zero for success and one for failure. These are analogous to the exit status of a command line program. Where zero indicates that a program finished running successfully. And one or any other number indicates that there was an error of some kind. What this return or exit status lets us do is treat the expression as a truth value. That becomes important when we combine these tests and comparisons with flow control structures. Like if or while.&lt;/li&gt;
&lt;li&gt;Lets test some string charatacters and see if they are equal or not equal.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"cat"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"cat"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt;
0
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"cat"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"dog"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt;
1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To point out the difference between testing strings and testing numbers. While we might be used to using greater than, less than, and equal signs to compare numbers, in the Test built-in, those are reserved for comparing strings. Strings can be greater or less than each other in the sense that the characters contained within them come earlier or later in the character set.&lt;/li&gt;
&lt;li&gt;And we can use tests to compare numeric values too. &lt;/li&gt;
&lt;li&gt;To compare numbers, we'll use different operators with a dash &lt;code&gt;(-)&lt;/code&gt; instead &lt;code&gt;-lt&lt;/code&gt; stands for less than.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; 4 &lt;span class="nt"&gt;-lt&lt;/span&gt; 3 &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; 
1
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; 4 &lt;span class="nt"&gt;-gt&lt;/span&gt; 3 &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; 
0

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can also negate or invert a test by using the exclamation mark character in front of the test expression.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; 4 &lt;span class="nt"&gt;-gt&lt;/span&gt; 3 &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; 
1
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;It's important to keep spaces between the brackets and arguments and operators. The test won't work if they're all squished together.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Comparing values with extended &lt;code&gt;test&lt;/code&gt; or &lt;code&gt;[[ ... ]]&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;In addition to the single bracket test notation, Bash gives us the double bracket notation called extended test. As with test, it's important to keep spaces between the sets of brackets and the expression we want to evaluate. &lt;/li&gt;
&lt;li&gt;Extended test gives us the same operations as test and adds a few other helpful features. With extended test, we can use more than one expression within a test to create a little bit more complex logic. For example, I can ask whether my home directory is a directory and whether the Bash binary exists. That set of statements is true.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt; 8 &lt;span class="nt"&gt;-lt&lt;/span&gt; 5 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; 
1
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; ~ &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; /root/etc/ &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt;
1
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; ~ &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; /root/etc/ &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt;
0
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; ~ &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; /var/tmp &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt;
0
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can also use these logical operators outside the extended test brackets to run commands conditionally. For example, we can write a test to see if the home directory is a directory. Then add two ampersands and then add an echo statement and because the test returns success Bash then goes on to run the echo statement. If the test fails, the echo statement doesn't run.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; ~ &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; ~ is a directory 
/home/danish is a directory
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; /bin/bash &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; /bin/bash is a directory 
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; 
1
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The test can also be replaced with a command because commands return an exit status too. For example, We could write ls, double ampersand, and then the text listed the directory. If the command completes my echo statement will be displayed.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Directory is listed successfully"&lt;/span&gt;
 10.197.192.171_dsm_cleanup_upgrade.out  &lt;span class="s1"&gt;'Calibre Library'&lt;/span&gt;   dir1   dk-img1.qcow2   Downloads      Music      Public   stopwatch.sh   union
 10.197.192.174_dsm_cleanup_upgrade.out   Desktop            dir2   Documents       fortanix.gpg   Pictures   snap     Templates      Videos
Directory is listed successfully
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Also, there are two built ins called &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; that you can use to generate a success or failure return code. Here, for example, we see the result of running true and an echo statement followed by the result of running false and an echo statement.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Will print the ECHO'&lt;/span&gt;
Will print the ECHO
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; 
0
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'Will not print the ECHO'&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; 
1
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Another useful feature that extended test provides is regular expression matching. To use that, I'll provide a string and then write equals tilde and then provide a regular expression to try to match to the string. This test succeeds because the string cat starts with C followed by a number of characters. If I change my string to zat, the test will fail.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"cat"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ c.&lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; 
0
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"zat"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ c.&lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; 
1
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Tests and comparisons are extremely common in Bash scripts so it's good to be as familiar with them as you can be. &lt;/li&gt;
&lt;li&gt;When writing your script, it's usually best to stick to using the extended test rather than switching between it and regular test. Doing so maintains consistency and ensures you have more features available to you. But if your script needs to be portable to other shells you'll want to use regular tests instead even though you'll lose some features. &lt;/li&gt;
&lt;li&gt;Now that we know how to get a true or false value out of a comparison or test we can use &lt;code&gt;test&lt;/code&gt; to provide control flow in our scripts. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Formatting and styling text output
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Let's move to working with text for a while. &lt;/li&gt;
&lt;li&gt;One option offered by the Echo built-in is &lt;code&gt;echo - e&lt;/code&gt; which tells Bash to interpret escaped characters or sequences which can be used to enhance text output. &lt;/li&gt;
&lt;li&gt;Escape sequences can represent special characters like tab, new line or the bell and they can be used to change the color of text in the terminal as well. &lt;/li&gt;
&lt;li&gt;When we write script, we'll often want to format text to line it up in columns or indent it and the tab character plays a role there.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Name&lt;/span&gt;&lt;span class="se"&gt;\t\t&lt;/span&gt;&lt;span class="s2"&gt;Number"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Scott&lt;/span&gt;&lt;span class="se"&gt;\t\t&lt;/span&gt;&lt;span class="s2"&gt;123"&lt;/span&gt;
Name&lt;span class="se"&gt;\t\t&lt;/span&gt;Number
Scott&lt;span class="se"&gt;\t\t&lt;/span&gt;123
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"Name&lt;/span&gt;&lt;span class="se"&gt;\t\t&lt;/span&gt;&lt;span class="s2"&gt;Number"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"Scott&lt;/span&gt;&lt;span class="se"&gt;\t\t&lt;/span&gt;&lt;span class="s2"&gt;123"&lt;/span&gt;
Name        Number
Scott       123
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"This text&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;break in&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;three lines"&lt;/span&gt;
This text
&lt;span class="nb"&gt;break &lt;/span&gt;&lt;span class="k"&gt;in
&lt;/span&gt;three lines
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Formatting output with &lt;code&gt;printf&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;As we've seen with echo composing strings that include variables or other data can get a little bit tedious, and so I want to show you another way to do it. &lt;/li&gt;
&lt;li&gt;The printf builtin gives us the ability to use placeholders when we compose strings and format values in ways that can make our script and our output look cleaner and more organized. &lt;/li&gt;
&lt;li&gt;Let's compare getting the same output result with both echo and printf.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"The results are: &lt;/span&gt;&lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;&lt;span class="s2"&gt; and &lt;/span&gt;&lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
The results are: 4 and 3
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"The results are: %d and %d&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;
The results are: 4 and 3
danish@danish-Ubuntu:~&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The first &lt;code&gt;%d&lt;/code&gt; prints the first value and the 2nd &lt;code&gt;printf&lt;/code&gt; the next subsequent value.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using printf, we'll write the literal parts of our string, the parts that don't change, and instead of putting Bash code mixed in with the string we use a placeholder wherever a dynamic value, one that will be the result of something our script runs will go and then at the end of the line we'll put whatever code we'll provide those values in the same sequence we used for the placeholders. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If we provide more values than there are placeholders we discover another useful feature of printf. It will repeat the output for each input it's given. The placeholder %d here represents a digit and a placeholder of %s represents a string value in this comparison below.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s2"&gt;"The results are: %d&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt; &lt;span class="k"&gt;$((&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="k"&gt;))&lt;/span&gt;
The results are: 4
The results are: 3
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The printf statement is longer than the echo statement that prints the same text but it can be easier to read and easier to work with. &lt;/li&gt;
&lt;li&gt;In simpliar terms :-&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%d&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Digit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%s&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Strings&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;For more info check &lt;code&gt;man 3 printf&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A benefit of &lt;code&gt;printf&lt;/code&gt; is that it lets us format output a little bit more easily than with echo. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Working with Arrays in Bash
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When writing scripts, we'll sometimes need to store pieces of information that contain more than one variable. While we can always create a new variable for any piece of information we need to store, that can become difficult to track and maintain. &lt;/li&gt;
&lt;li&gt;Arrays allow us to store related pieces of information and to refer to them more easily. &lt;/li&gt;
&lt;li&gt;Bash supports two kinds of array: 

&lt;ul&gt;
&lt;li&gt;Indexed arrays   i.e. (Values with positioned Index)&lt;/li&gt;
&lt;li&gt;Associative arrays  i.e. (Key and Value), used by &lt;code&gt;declare -A XXX&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;In an indexed array, we set or read pieces of information by referring to their position in the list, or their index. We can define an indexed array implicitly by providing a list of values within parenthesis and assigning a name.&lt;/li&gt;

&lt;li&gt; Each term, double quotes separated by a space, and then a closing parenthesis, or we can do this explicitly using declare dash a. There's an array named snacks with three elements inside it. There aren't commas between elements like there are in other languages.
&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ snacks&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="s2"&gt;"apple"&lt;/span&gt; &lt;span class="s2"&gt;"banana"&lt;/span&gt; &lt;span class="s2"&gt;"orange"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$snacks&lt;/span&gt;
apple
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;snacks&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
apple banana orange
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nv"&gt;snacks&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="s2"&gt;"apple"&lt;/span&gt; &lt;span class="s2"&gt;"banana"&lt;/span&gt; &lt;span class="s2"&gt;"orange"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;snacks&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
apple banana orange
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To retrieve an element inside an array, will use its zero based notation along with a variable name inside of curly braces. In this case, orange, since it's at index two, the third element. Apple is at index zero, and banana is at index one.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;snacks&lt;/span&gt;&lt;span class="p"&gt;[0]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
apple
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;snacks&lt;/span&gt;&lt;span class="p"&gt;[1]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
banana
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;snacks&lt;/span&gt;&lt;span class="p"&gt;[2]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
orange
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can also set array values by index number. We can write snacks, and then in square brackets I'll provide the index five, and set that equal to grapes. And we don't have to populate every element. These sparse arrays can be very useful when you need to record data with a particular position in a list instead of just adding on to the end of the array.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;snacks[5]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"grapes"&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;snacks+&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="s2"&gt;"mango"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;snacks&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
apple banana orange grapes mango
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;But when we print the same we are not having the empty spaces printed thus to print that we can do the below:-
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;0..6&lt;span class="o"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;snacks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done
&lt;/span&gt;0: apple
1: banana
2: orange
3: 
4: 
5: grapes
6: mango
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If you're using Bash version four, and above, we can also make associative arrays. That is, we can specify a key and a value instead of just a list of values with positional index values. To do this, we'll use the below example:-
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-A&lt;/span&gt; office
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;office[city]&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"San Francisco"&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;office[&lt;span class="s2"&gt;"building name"&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;&lt;span class="s2"&gt;"HQ West"&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;office&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"building name"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; is &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;office&lt;/span&gt;&lt;span class="p"&gt;[city]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
HQ West is &lt;span class="k"&gt;in &lt;/span&gt;San Francisco
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If you're using Bash3 or below, you won't have support for associative arrays, so keep that in mind when you're building your script. &lt;/li&gt;
&lt;li&gt;Associative arrays and indexed arrays are both limited to one level or layer, so we can't create an array with an array inside of it, or a nested array, in Bash. &lt;/li&gt;
&lt;li&gt;If you find yourself needing to represent data in a nested array, that's usually a good sign that it's time to move on from Bash and start writing your program in another, more suitable language. &lt;/li&gt;
&lt;li&gt;Your script may benefit from using arrays, or you may not use them at all. &lt;/li&gt;
&lt;li&gt;In many situations, the same information can be stored as single variables in an indexed array or in an associative array. What you choose to use comes down to how you want to model, think about, and use whatever data your program needs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Control structures in Bash
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Conditional statements with the "if" keyword
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When we write scripts, we'll often use control structures, which instead of just running script commands from the top down one after the other, give us the opportunity to control and change how script commands are executed based on conditions we specify. &lt;/li&gt;
&lt;li&gt;One of these control structures is an &lt;code&gt;if&lt;/code&gt; statement. And an &lt;code&gt;if&lt;/code&gt; statement runs or executes code based on the truth value of a given expression. &lt;/li&gt;
&lt;li&gt;In Bash, that takes the form of if, followed by an expression from which we'll get a true or false value followed with a keyword then.&lt;/li&gt;
&lt;li&gt;That's followed by script lines to run, if the condition evaluates as true. We can end the if statement there with fi, the word if spelled backwards, or we can add an else statement and provide script to run, if the condition evaluates as false. &lt;/li&gt;
&lt;li&gt;The condition is something that returns a truth value, often the extended test with two brackets, but it can also be the older single bracket or an arithmetic evaluation. &lt;/li&gt;
&lt;li&gt;It can also be a command, because remember, commands always finish with a zero or non-zero status interpreted as true or false.&lt;/li&gt;
&lt;li&gt;In fact, when you're experimenting, it can be useful to use the true and false commands in your if statements to guarantee a particular result.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Working with "while" and "until" loops
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Loops are control structures that run a specific piece of code over and over until the loop is caused to end.&lt;/li&gt;
&lt;li&gt;There's two kinds of loops that are dependent on conditions, called 

&lt;ul&gt;
&lt;li&gt;while loops&lt;/li&gt;
&lt;li&gt;until loops. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;The while loop runs for the duration of time when its condition is true and stops when that condition becomes false.&lt;/li&gt;

&lt;li&gt;The until loop runs for the duration of time when its condition is false and stops when that condition becomes true.&lt;/li&gt;

&lt;li&gt;Both types of loops start with the appropriate keyword and the condition to use to determine whether the loop should keep running. That's followed by do and the code to loop through. And then the construct ends with done.
&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"While Loop"&lt;/span&gt;

&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nv"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;((&lt;/span&gt; n &amp;lt; 10 &lt;span class="o"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"n:&lt;/span&gt;&lt;span class="nv"&gt;$n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="o"&gt;((&lt;/span&gt; n++ &lt;span class="o"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;done

&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;Until Loop"&lt;/span&gt;
&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nv"&gt;m&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0
&lt;span class="k"&gt;until&lt;/span&gt; &lt;span class="o"&gt;((&lt;/span&gt; m &lt;span class="o"&gt;==&lt;/span&gt; 10 &lt;span class="o"&gt;))&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"m:&lt;/span&gt;&lt;span class="nv"&gt;$m&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="o"&gt;((&lt;/span&gt; m++ &lt;span class="o"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Introducing "for" loops
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A for loop takes a list or range of values and runs code once for each value in that list. Each iteration of the loop, each time the loop runs, a variable within the loop represents the current item in the list.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in &lt;/span&gt;1 2 3
&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;
&lt;span class="k"&gt;done

for &lt;/span&gt;i &lt;span class="k"&gt;in &lt;/span&gt;1 2 3&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;1..100&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;((&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1&lt;span class="p"&gt;;&lt;/span&gt; i&amp;lt;&lt;span class="o"&gt;=&lt;/span&gt;100&lt;span class="p"&gt;;&lt;/span&gt; i++ &lt;span class="o"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nv"&gt;fruits&lt;/span&gt;&lt;span class="o"&gt;=(&lt;/span&gt;&lt;span class="s2"&gt;"apple"&lt;/span&gt; &lt;span class="s2"&gt;"banana"&lt;/span&gt; &lt;span class="s2"&gt;"cherry"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;i &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;do
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$i&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Selecting behavior using "case"
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The case statement is a control structure which lets us define code to run based on particular conditions. &lt;/li&gt;
&lt;li&gt;We provide it a series of values and whichever one matches the given input is what Bash runs. &lt;/li&gt;
&lt;li&gt;A case statement starts out with the word &lt;code&gt;case&lt;/code&gt; followed by a variable that you're testing and the word &lt;code&gt;in&lt;/code&gt; and ends with &lt;code&gt;esac&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="nv"&gt;animal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"dog"&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nv"&gt;$animal&lt;/span&gt; &lt;span class="k"&gt;in
    &lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Feline"&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
    dog|wolf&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Canine"&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
    &lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"No match!
esac
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$.&lt;/span&gt;/case_statement.sh 
Canine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If we change the value then see the output
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class="nv"&gt;animal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Monkey"&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nv"&gt;$animal&lt;/span&gt; &lt;span class="k"&gt;in
    &lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Feline"&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
    dog|wolf&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Canine"&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
    &lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"No match!"&lt;/span&gt;
&lt;span class="k"&gt;esac&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Output of script
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;./case_statement.sh 
No match!
danish@danish-Ubuntu:~&lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using functions in Bash
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;During your script development, you may find yourself repeating the same set of commands, or writing very similar commands while changing just one or two parameters. &lt;/li&gt;
&lt;li&gt;It's a good practice to not repeat yourself if you don't have to. And keeping scripts organized without duplication makes them a lot more maintainable too.&lt;/li&gt;
&lt;li&gt;To help organize code, we can use functions, which let us write a set of commands once and then refer to that code by name whenever we need to run it. &lt;/li&gt;
&lt;li&gt;To create a function, we'll give the function a name, in this case the name fname, and follow that with open and close parentheses. And then we'll add a set of braces to enclose commands that will make up the function.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

greet&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hi there."&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"And now, a greeting..."&lt;/span&gt;
greet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;I'll use the variable, $1, which represents the first argument passed into a function. I'll save my script and run it again. Here I see my name passed into the function, greet. $1 represents the first argument pass and other arguments can follow that pattern. $2 is the second argument, $3 is the third, and so on.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

greet&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello, &lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;

greet Danish
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Greetings, Please tell me How are you?"&lt;/span&gt;
danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;./functions_check.sh 
Hello, Danish
Greetings, Please tell me How are you?

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

greet&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello there &lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;. What a nice &lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;."&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

greet Danish Morning
greet Everybody Evening

danish@danish-Ubuntu:~&lt;span class="nv"&gt;$ &lt;/span&gt;./functions_check.sh 
Hello there Danish. What a &lt;span class="nb"&gt;nice &lt;/span&gt;Morning.
Hello there Everybody. What a &lt;span class="nb"&gt;nice &lt;/span&gt;Evening.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;There's a few more special variables that we can use inside a function too, and those are &lt;code&gt;$@&lt;/code&gt; and $FUNCNAME. &lt;code&gt;@&lt;/code&gt; represents all of the arguments given to the function, which can be useful for looping through the arguments if your script calls for that.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

numberthing&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
    &lt;span class="k"&gt;for &lt;/span&gt;f &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
        &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$i&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        &lt;span class="o"&gt;((&lt;/span&gt; i +&lt;span class="o"&gt;=&lt;/span&gt; 1 &lt;span class="o"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;done
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"This counting was brought to you by &lt;/span&gt;&lt;span class="nv"&gt;$FUNCNAME&lt;/span&gt;&lt;span class="s2"&gt;."&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

numberthing &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; /&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;echo
&lt;/span&gt;numberthing pine birch maple spruce
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class="nv"&gt;var1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"I'm variable 1"&lt;/span&gt;

myfunction&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;var2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"I'm variable 2"&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;var3&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"I'm variable 3"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
myfunction

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$var1&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$var2&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$var3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>bash</category>
      <category>scripting</category>
      <category>sre</category>
      <category>devops</category>
    </item>
    <item>
      <title>Understanding `kube-system` in Kubernetes: A City Analogy You’ll Never Forget</title>
      <dc:creator>Danish Khan</dc:creator>
      <pubDate>Sun, 27 Jul 2025 01:28:34 +0000</pubDate>
      <link>https://forem.com/deekay99/understanding-kube-system-in-kubernetes-a-city-analogy-youll-never-forget-2ek7</link>
      <guid>https://forem.com/deekay99/understanding-kube-system-in-kubernetes-a-city-analogy-youll-never-forget-2ek7</guid>
      <description>&lt;h2&gt;
  
  
  🧱 The Analogy: Kubernetes as a Smart City
&lt;/h2&gt;

&lt;p&gt;Imagine Kubernetes as a &lt;strong&gt;modern smart city&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Now, within this city:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🏢 &lt;strong&gt;Pods&lt;/strong&gt; = Buildings or Shops
&lt;/li&gt;
&lt;li&gt;🧑‍💼 &lt;strong&gt;Deployments&lt;/strong&gt; = City Planners or Construction Managers
&lt;/li&gt;
&lt;li&gt;🛣️ &lt;strong&gt;Services&lt;/strong&gt; = Roads &amp;amp; Signboards that help people reach buildings
&lt;/li&gt;
&lt;li&gt;🧱 &lt;strong&gt;Nodes&lt;/strong&gt; = City Blocks where buildings stand
&lt;/li&gt;
&lt;li&gt;🧭 &lt;strong&gt;Ingress&lt;/strong&gt; = City’s Gateways or Entry Checkpoints
&lt;/li&gt;
&lt;li&gt;📜 &lt;strong&gt;ConfigMaps/Secrets&lt;/strong&gt; = City Rulebooks and Vaults
&lt;/li&gt;
&lt;li&gt;🛠️ &lt;strong&gt;kube-system&lt;/strong&gt; = Municipal Headquarters&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🏛️ What is &lt;code&gt;kube-system&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;kube-system&lt;/code&gt; namespace is like the &lt;strong&gt;City’s Municipal Office&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You &lt;strong&gt;don’t see it on the news&lt;/strong&gt;, but it's what &lt;strong&gt;keeps the entire city running&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You wouldn’t open a café or bank inside your city’s electrical grid control room, right?&lt;br&gt;&lt;br&gt;
Similarly, you shouldn’t deploy your app inside &lt;code&gt;kube-system&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧠 Memorize This for Life:
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"If Kubernetes is a City, then &lt;code&gt;kube-system&lt;/code&gt; is its Municipality – invisible to citizens but absolutely vital."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🛠️ What Runs Inside &lt;code&gt;kube-system&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;Let’s break down some key pods and their real-world equivalents:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Kubernetes Component&lt;/th&gt;
&lt;th&gt;Real-World Analogy&lt;/th&gt;
&lt;th&gt;Role in the City (Cluster)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;kube-dns&lt;/code&gt; / &lt;code&gt;CoreDNS&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;📇 Address Lookup Office&lt;/td&gt;
&lt;td&gt;Resolves service names to IP addresses&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;kube-proxy&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;🚦 Traffic Police&lt;/td&gt;
&lt;td&gt;Controls how traffic flows between buildings&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;etcd&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;🗃️ City’s Memory Archive&lt;/td&gt;
&lt;td&gt;Stores all official records (K8s config/state data)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;kube-scheduler&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;🏗️ Construction Allocator&lt;/td&gt;
&lt;td&gt;Decides which block gets which new building (Pod)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;kube-controller-manager&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;📋 Mayor's Secretariat&lt;/td&gt;
&lt;td&gt;Ensures reality matches the city’s blueprints&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;metrics-server&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;🧑‍⚕️ Health Inspector&lt;/td&gt;
&lt;td&gt;Monitors health across city buildings&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🚫 Why You Shouldn’t Deploy Apps in &lt;code&gt;kube-system&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Because it’s &lt;strong&gt;not meant for public use&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
It’s like trying to open your food truck inside the electricity board’s server room.&lt;/p&gt;

&lt;p&gt;Your apps belong in &lt;strong&gt;dedicated districts&lt;/strong&gt; like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;default&lt;/code&gt; (for general use)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dev&lt;/code&gt;, &lt;code&gt;stage&lt;/code&gt;, &lt;code&gt;prod&lt;/code&gt; (for environment segregation)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;team-a&lt;/code&gt;, &lt;code&gt;team-b&lt;/code&gt; (for multi-team setups)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep &lt;code&gt;kube-system&lt;/code&gt; reserved for core city operations!&lt;/p&gt;




&lt;h2&gt;
  
  
  📸 Quick Commands to Peek into kube-system
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get pods &lt;span class="nt"&gt;-n&lt;/span&gt; kube-system
kubectl describe pod &amp;lt;pod-name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; kube-system
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use these to inspect what your Kubernetes "municipal office" is doing.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧱 Brick-by-Brick Learning That Will Grow
&lt;/h2&gt;

&lt;p&gt;In this “Kubernetes is a City” model, we’ll continue using this analogy for upcoming topics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deployments = City Builders&lt;/li&gt;
&lt;li&gt;Services = Transport and Signage&lt;/li&gt;
&lt;li&gt;Ingress = Entry Checkpoints&lt;/li&gt;
&lt;li&gt;Volumes = Storage Units&lt;/li&gt;
&lt;li&gt;Secrets = Vaults &amp;amp; Lockers&lt;/li&gt;
&lt;li&gt;So whenever you get confused, just go back to the city map 🗺️.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🚀 Final Thought
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You don’t need to memorize everything.Just understand the city, and the rest will make sense.&lt;/li&gt;
&lt;li&gt;Stay tuned for the next brick — we’ll build this DevOps city together!&lt;/li&gt;
&lt;/ul&gt;




&lt;ul&gt;
&lt;li&gt;Written ✍️ for beginners stepping into the magical (and sometimes mystifying) world of Kubernetes. If you found this helpful, follow me for more ‘brick-by-brick’ DevOps analogies!&lt;/li&gt;
&lt;li&gt;Let me know when you’re ready for the &lt;strong&gt;next brick&lt;/strong&gt;, like explaining &lt;strong&gt;Deployments&lt;/strong&gt;, &lt;strong&gt;Services&lt;/strong&gt;, or &lt;strong&gt;Ingress&lt;/strong&gt;, and I’ll extend the city analogy accordingly.&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>kubernetes</category>
      <category>docker</category>
      <category>devops</category>
      <category>sre</category>
    </item>
    <item>
      <title>Demystifying Docker Multi-Platform Builds and Manifests: A Brick by Brick Guide</title>
      <dc:creator>Danish Khan</dc:creator>
      <pubDate>Wed, 09 Jul 2025 17:58:25 +0000</pubDate>
      <link>https://forem.com/deekay99/demystifying-docker-multi-platform-builds-and-manifests-a-brick-by-brick-guide-4kma</link>
      <guid>https://forem.com/deekay99/demystifying-docker-multi-platform-builds-and-manifests-a-brick-by-brick-guide-4kma</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;🧱 &lt;em&gt;"One image. Multiple platforms. Zero surprises."&lt;/em&gt;&lt;br&gt;&lt;br&gt;
This is what Docker's multi-platform build and manifest system enables — and it's more relevant than ever in today’s hybrid infrastructure world.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Whether you’re:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Working on an M1 Mac but deploying to an x86 GKE cluster,&lt;/li&gt;
&lt;li&gt;Building in CI/CD on an ARM-based runner but targeting AMD64 servers,&lt;/li&gt;
&lt;li&gt;Or managing both OpenShift on-prem and GKE on cloud...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You need to &lt;strong&gt;build and tag Docker images the right way&lt;/strong&gt; — to ensure your containers run reliably, regardless of where they're pulled.&lt;/p&gt;

&lt;p&gt;In this article, we’ll go brick by brick to explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ What is a multi-platform image build?&lt;/li&gt;
&lt;li&gt;✅ Why does Docker pull different images on different machines?&lt;/li&gt;
&lt;li&gt;✅ What exactly is a manifest and why does it matter?&lt;/li&gt;
&lt;li&gt;✅ How to enforce platform consistency across builds?&lt;/li&gt;
&lt;li&gt;✅ What breaks if you don’t use platform-aware builds?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And we’ll wrap it all up with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🧠 Real-world DevOps gotchas&lt;/li&gt;
&lt;li&gt;🛠️ Best practices for Jenkins and CI/CD pipelines&lt;/li&gt;
&lt;li&gt;📦 Storage and runtime behavior of platform-specific layers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s get started. 🔍&lt;/p&gt;




&lt;h2&gt;
  
  
  🧱 What is a Docker Multi-Platform Build?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;multi-platform build&lt;/strong&gt; allows you to create Docker images that can run on multiple CPU architectures (like &lt;code&gt;amd64&lt;/code&gt;, &lt;code&gt;arm64&lt;/code&gt;) from a single machine — even if that machine only supports one architecture.&lt;/p&gt;

&lt;h3&gt;
  
  
  🧠 Why It Matters
&lt;/h3&gt;

&lt;p&gt;Different environments use different processor types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🖥️ Intel/AMD laptops and servers → &lt;code&gt;amd64&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;🍏 Apple M1/M2 Macs → &lt;code&gt;arm64&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;📦 Raspberry Pi → &lt;code&gt;armhf&lt;/code&gt;, &lt;code&gt;arm64&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;☁️ AWS Graviton or GCP Tau T2A → &lt;code&gt;arm64&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you don’t build platform-aware images, your container might &lt;strong&gt;fail to run&lt;/strong&gt; on systems it wasn’t built for.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔍 How Docker Identifies Your Architecture Automatically
&lt;/h2&gt;

&lt;p&gt;When you run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull busybox
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Docker &lt;strong&gt;automatically knows your architecture&lt;/strong&gt; using system calls like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;uname&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt;     &lt;span class="c"&gt;# Returns x86_64 or arm64&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It uses this info to &lt;strong&gt;pull the correct platform image&lt;/strong&gt; by default — no need for you to explicitly specify the platform unless you're cross-building.&lt;/p&gt;




&lt;h2&gt;
  
  
  📦 Why SHA256 Digests Differ for Each Platform
&lt;/h2&gt;

&lt;p&gt;Even if the tag is the same (&lt;code&gt;busybox:latest&lt;/code&gt;), the actual &lt;strong&gt;SHA256 digest is different&lt;/strong&gt; for &lt;code&gt;amd64&lt;/code&gt; vs &lt;code&gt;arm64&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Each platform compiles binaries differently, so:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Different binaries = different layers&lt;/li&gt;
&lt;li&gt;Different layers = different image digests&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🤔 What Happens If I Pull Two Platform Variants?
&lt;/h2&gt;

&lt;p&gt;Let’s say you do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull &lt;span class="nt"&gt;--platform&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;linux/arm64 busybox
docker tag busybox busybox:arm64

docker pull &lt;span class="nt"&gt;--platform&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;linux/amd64 busybox
docker tag busybox busybox:amd64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you have &lt;strong&gt;two tagged variants&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But if you just do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run busybox
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will run &lt;strong&gt;the latest pulled &lt;code&gt;busybox:latest&lt;/code&gt;&lt;/strong&gt;, which may or may not match your expected platform.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Best Practice:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Explicitly tag and run&lt;/strong&gt; the desired platform image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run busybox:arm64
docker run busybox:amd64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ⚙️ How to Enforce Platform in Docker Build
&lt;/h2&gt;

&lt;p&gt;If you're using a CI/CD pipeline (like Jenkins) or building locally, &lt;strong&gt;always fix the platform&lt;/strong&gt; to avoid surprises:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker buildx create &lt;span class="nt"&gt;--use&lt;/span&gt;   &lt;span class="c"&gt;# once per agent&lt;/span&gt;
docker buildx build &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--platform&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;linux/amd64 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-t&lt;/span&gt; myimage:1.0.0 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--push&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures the image is always built for &lt;code&gt;amd64&lt;/code&gt;, regardless of whether you're on M1, x86, or in the cloud.&lt;/p&gt;




&lt;h2&gt;
  
  
  📍 Real-World Use Case: Same Image for On-Prem &amp;amp; Cloud
&lt;/h2&gt;

&lt;p&gt;Assume you’re running:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On-prem OpenShift (OCP) setup&lt;/li&gt;
&lt;li&gt;Target deployment on GCP GKE&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even if &lt;strong&gt;both runtime platforms are &lt;code&gt;amd64&lt;/code&gt;&lt;/strong&gt;, your &lt;strong&gt;CI runner&lt;/strong&gt; may be &lt;code&gt;arm64&lt;/code&gt; (e.g., running on M1 Mac or ARM-based VM). If you don’t specify &lt;code&gt;--platform&lt;/code&gt;, your build may &lt;strong&gt;accidentally produce an &lt;code&gt;arm64&lt;/code&gt; image&lt;/strong&gt;, which &lt;strong&gt;won’t work&lt;/strong&gt; in production.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Solution
&lt;/h3&gt;

&lt;p&gt;In Jenkins or your build script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker buildx build &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--platform&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;linux/amd64 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-t&lt;/span&gt; registry.io/myapp:1.0.0 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--push&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also &lt;strong&gt;verify the platform&lt;/strong&gt; post-build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker image inspect myapp:1.0.0 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--format&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{{.Architecture}}/{{.Os}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  📈 Will Multi-Platform Build Increase Image Size?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Registry Size:
&lt;/h3&gt;

&lt;p&gt;✅ &lt;strong&gt;Yes&lt;/strong&gt;, total size increases because each architecture has its own full image:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;amd64&lt;/code&gt;: 100MB&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;arm64&lt;/code&gt;: 90MB
→ Registry now stores ~190MB&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Local Size:
&lt;/h3&gt;

&lt;p&gt;❌ &lt;strong&gt;No&lt;/strong&gt;, unless you &lt;code&gt;--load&lt;/code&gt; all variants locally (default keeps only the last one).&lt;/p&gt;

&lt;h3&gt;
  
  
  Runtime Download:
&lt;/h3&gt;

&lt;p&gt;✅ Efficient — Docker pulls only the matching platform image for the host.&lt;/p&gt;




&lt;h2&gt;
  
  
  📜 Deep Dive into Docker Manifests
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🤖 What is a Manifest?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Docker manifest&lt;/strong&gt; is a metadata file that maps a &lt;strong&gt;Docker image tag&lt;/strong&gt; to the correct image version &lt;strong&gt;for each platform&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Think of it as a:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;📦 Smart label that says “if you’re on &lt;code&gt;amd64&lt;/code&gt;, pull this; if &lt;code&gt;arm64&lt;/code&gt;, pull that.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It allows the same tag (&lt;code&gt;myapp:latest&lt;/code&gt;) to &lt;strong&gt;point to multiple images&lt;/strong&gt;, depending on who’s asking.&lt;/p&gt;




&lt;h3&gt;
  
  
  📖 Real-World Analogy
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;🍔 A restaurant has one menu item: &lt;strong&gt;"Burger"&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
If an Indian orders, they get a &lt;strong&gt;veg burger&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
If an American orders, they get a &lt;strong&gt;beef burger&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
If a Middle Easterner orders, they get a &lt;strong&gt;lamb burger&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;They all just said “burger” — but they got &lt;strong&gt;what’s right for them&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Similarly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull myapp:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;returns a platform-specific image — thanks to the manifest.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔬 What’s Inside a Manifest?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"manifests"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"platform"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"architecture"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"amd64"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"os"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"linux"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"digest"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sha256:aaa..."&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"platform"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"architecture"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arm64"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"os"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"linux"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"digest"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sha256:bbb..."&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔍 How to Inspect a Manifest
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker buildx imagetools inspect myapp:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  ✅ What Problems It Solved
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Problem&lt;/th&gt;
&lt;th&gt;Solved By Manifest&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;One tag = one platform only&lt;/td&gt;
&lt;td&gt;One tag supports many platforms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Manual selection of image&lt;/td&gt;
&lt;td&gt;Automatic matching by Docker&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Broken builds on ARM/M1&lt;/td&gt;
&lt;td&gt;Seamless image pulls&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multiple tags to manage&lt;/td&gt;
&lt;td&gt;Single tag, multi-arch supported&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  ✅ Final Best Practices Summary
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Task&lt;/th&gt;
&lt;th&gt;Recommendation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;CI builds on mixed-arch runners&lt;/td&gt;
&lt;td&gt;Always use &lt;code&gt;--platform&lt;/code&gt; in &lt;code&gt;docker buildx build&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multi-platform support&lt;/td&gt;
&lt;td&gt;Build with &lt;code&gt;--platform=linux/amd64,linux/arm64&lt;/code&gt; and push manifest&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Save registry space&lt;/td&gt;
&lt;td&gt;Build only required platforms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Keep platform control&lt;/td&gt;
&lt;td&gt;Tag each variant explicitly (e.g., &lt;code&gt;myapp:arm64&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Validate architecture&lt;/td&gt;
&lt;td&gt;Use &lt;code&gt;docker inspect&lt;/code&gt; or CI assertions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🔚 Conclusion
&lt;/h2&gt;

&lt;p&gt;Understanding Docker’s multi-platform builds and manifests is essential in today’s hybrid infrastructure world. Whether you're building locally, on Jenkins, deploying to GKE, or OpenShift — &lt;strong&gt;platform consistency matters&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;One tag. Many platforms. No surprises.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
That's the power of Docker Manifests.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Want to learn how to write your own manifest manually or automate this via Jenkins or GitHub Actions? Comment or connect — happy to help!&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
      <category>platform</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Understanding Docker Layer Caching: Why It Matters for DevOps Engineers</title>
      <dc:creator>Danish Khan</dc:creator>
      <pubDate>Sat, 05 Jul 2025 23:48:54 +0000</pubDate>
      <link>https://forem.com/deekay99/understanding-docker-layer-caching-why-it-matters-for-devops-engineers-b81</link>
      <guid>https://forem.com/deekay99/understanding-docker-layer-caching-why-it-matters-for-devops-engineers-b81</guid>
      <description>&lt;p&gt;As a DevOps engineer diving deep into containerization, I recently asked myself a seemingly simple question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“When Docker builds an image, how exactly does it cache layers — and does understanding this really matter in real-world scenarios?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Turns out, it does — a lot more than I thought.&lt;/p&gt;

&lt;p&gt;Let’s explore how Docker caches image layers, why it does so, and how understanding this helps in real CI/CD pipelines and production builds.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧱 Dockerfile: Every Instruction Is a Layer
&lt;/h2&gt;

&lt;p&gt;Each line in your Dockerfile becomes a new layer in your image. Docker builds images step by step — and tries to cache each step to speed things up.&lt;/p&gt;

&lt;p&gt;Here’s a simple Dockerfile to illustrate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; ubuntu:20.04&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;apt-get update
&lt;span class="k"&gt;RUN &lt;/span&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; curl
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . /app&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["./start.sh"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Docker builds this from top to bottom. Each instruction like RUN or COPY is a layer, and Docker stores them in its local cache.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔁 How Docker Layer Caching Works
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;When Docker runs a build:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It looks at each instruction in the Dockerfile.&lt;/li&gt;
&lt;li&gt;If that instruction hasn't changed and all previous instructions are also cached, it reuses the existing cached layer.&lt;/li&gt;
&lt;li&gt;If a change is detected, all instructions after that point are rebuilt — no cache reuse beyond that.
You’ll see this during builds:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Step 2/5 : RUN apt-get update
 &lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Using cache
Step 3/5 : RUN apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; curl
 &lt;span class="nt"&gt;---&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Running &lt;span class="k"&gt;in &lt;/span&gt;abc123...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second instruction was cached. The third one was rebuilt — possibly because something changed or it wasn’t cached before.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Why This Matters in Real Life (Not Just Theory)
&lt;/h2&gt;

&lt;p&gt;Understanding layer caching helps in practical DevOps scenarios. Here’s where it makes a difference:&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ 1. Faster CI/CD Pipelines
&lt;/h3&gt;

&lt;p&gt;CI pipelines that rebuild Docker images frequently can benefit hugely from layer caching.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Place slow-changing instructions early (e.g., apt-get update, tool installs).&lt;/li&gt;
&lt;li&gt;Place frequently changing instructions later (e.g., COPY .).
This lets Docker skip as much work as possible in repeated builds.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🐞 2. Troubleshooting Build Failures
&lt;/h3&gt;

&lt;p&gt;Sometimes, caching hides problems. Maybe a stale file is being used due to cache.&lt;br&gt;
To force a clean build, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;--no-cache&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; myapp &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is helpful when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A file isn’t being copied as expected.&lt;/li&gt;
&lt;li&gt;An install command fails only in CI but works locally.&lt;/li&gt;
&lt;li&gt;Environment variables changed but not reflected.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  📦 3. Reduce Image Size (and Security Surface)
&lt;/h3&gt;

&lt;p&gt;Smaller images = faster pulls, better security.&lt;/p&gt;

&lt;p&gt;Combine commands like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;RUN apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; curl &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; /var/lib/apt/lists/&lt;span class="k"&gt;*&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This results in fewer layers, less bloat, and a tighter image.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔐 4. Security &amp;amp; Audits
&lt;/h3&gt;

&lt;p&gt;Understanding layer origins helps pinpoint:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When a vulnerable file was introduced.&lt;/li&gt;
&lt;li&gt;Which layer to rebuild to remove it.&lt;/li&gt;
&lt;li&gt;Which command added sensitive stuff.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔍 Inspecting Layers: docker history
&lt;/h2&gt;

&lt;p&gt;You can inspect image layers with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;history &lt;/span&gt;myapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This shows each Dockerfile instruction and how much space it added:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;IMAGE         CREATED         CREATED BY                     SIZE
abc123        10 seconds ago  RUN apt-get &lt;span class="nb"&gt;install &lt;/span&gt;curl       25MB
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Want to go deeper? Try &lt;code&gt;dive&lt;/code&gt; — it gives you a beautiful interactive CLI to explore each layer.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏁 TL;DR
&lt;/h2&gt;

&lt;p&gt;Docker caches each Dockerfile instruction (layer) if nothing has changed. As a DevOps engineer, understanding this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Speeds up your CI/CD builds.&lt;/li&gt;
&lt;li&gt;Helps troubleshoot weird Docker issues.&lt;/li&gt;
&lt;li&gt;Keeps your image sizes optimized.&lt;/li&gt;
&lt;li&gt;Gives you visibility into build and runtime behavior.
Next time your Docker build seems “weirdly fast” or “unexpectedly broken,” caching might be the hero or the culprit.&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>docker</category>
      <category>devops</category>
      <category>containers</category>
      <category>cicd</category>
    </item>
    <item>
      <title>Why I Started “DevOps Brick by Brick” — My Self-Taught DevOps/SRE/GitOps Journey</title>
      <dc:creator>Danish Khan</dc:creator>
      <pubDate>Tue, 01 Jul 2025 21:59:09 +0000</pubDate>
      <link>https://forem.com/deekay99/why-i-started-brick-by-brick-my-self-taught-devopssregitops-journey-38fd</link>
      <guid>https://forem.com/deekay99/why-i-started-brick-by-brick-my-self-taught-devopssregitops-journey-38fd</guid>
      <description>&lt;p&gt;Over the years, I realized that while working in tech, I was relying too much on prebuilt systems and quick fixes. I wanted to truly understand the tools I use daily — Docker, Kubernetes, Jenkins, GCP, GitOps, and beyond.&lt;/p&gt;

&lt;p&gt;This blog is my public notebook — documenting what I learn, how I debug, and how I grow as a self-taught DevOps/SRE engineer.&lt;/p&gt;

&lt;p&gt;I’ll be sharing bite-sized learnings, troubleshooting steps, and mini lab setups I build for myself. All with one motto in mind:&lt;/p&gt;

&lt;p&gt;🐟 I will not give a fish, I'll teach you how to fish.&lt;/p&gt;

&lt;p&gt;Welcome to "DevOps Brick by Brick" — let’s build this together.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>sre</category>
      <category>gitops</category>
      <category>selftaught</category>
    </item>
  </channel>
</rss>
