HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to BashNumbers & ArithmeticStringsArraysConditions (if)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output & Input
📦 Variables
🔢 Numbers & Arithmetic
✍️ Text
📋 Array
🔁 Condition & Loop
🧩 Functions & Pipes

Bash lessons

Command line power

Bash is a shell before being a programming language: when you type commands in the Linux and macOS terminal, you are talking to it. But when you write the same commands into a file and make it executable, you get a script, and Bash becomes a full-fledged scripting language.

The power of Bash comes not from the language itself, but from the tools it calls. You search with grep, replace with sed, split into columns with awk, download with curl, and connect them with the pipe symbol. Each tool has a single job and does it well; you build the workflow by chaining them together.

Anyone who manages servers, takes backups, processes log files, or handles deployments writes Bash. CI/CD pipeline steps, Docker image setups, and system maintenance tasks are largely Bash scripts. That is why Bash crosses your path no matter which branch of software development you are in.

📖 Command Reference→
  • •

    Introduction to Bash

    First step into Bash, the language of the command line: printing with echo and variables.

    →
  • •

    Numbers & Arithmetic

    Math operations and command substitution $( ) with $(( )).

    →
  • •

    Strings

    Length (${#name}), uppercase (${name^^}) and substring (${name:0:3}).

    →
  • •

    Arrays

    Array creation, accessing elements, and element count.

    →
  • •

    Conditions (if)

    Decision making and test operators (-eq, -lt, =) with if [ ].

    →
  • •

    Loops (for / while)

    Iterating over items/ranges with for and conditional repetition with while.

    →
  • •

    Functions

    Function definition and parameters ($1, $2).

    →

What you will learn

  • Printing output with echo and assigning variables
  • Capturing command output into a variable and chaining with pipes
  • Checking files and text using conditions
  • Working over file lists with for and while loops
  • Writing functions and passing parameters to a script
  • Safely stopping a script in case of errors

Who is this for?

  • System administrators and DevOps engineers who manage servers
  • Developers who want to automate repetitive tasks
  • Anyone who wants to feel comfortable in the Linux or macOS terminal

When to use?

Bash is the shortest path for file operations, backups, log processing, installation and deployment steps, and scheduled maintenance tasks — it connects already existing tools.

When a script exceeds a hundred lines, complex data structures are needed, or error handling gets serious, it is healthier to switch to Python. Array and text manipulation rules in Bash easily lead to mistakes.

Frequently asked questions

Are Bash and shell the same thing?

Shell is a general concept — the program that takes your commands and runs them. Bash is its most common example; sh, zsh, and fish are also shells. macOS now uses zsh by default, but Bash scripts continue to run.

Why can't I leave spaces when assigning variables?

Because when Bash sees spaces on either side of the equals sign, it considers it not an assignment but a command call and looks for the name as a program. The correct syntax has no spaces: name=value. This is the most common mistake when learning Bash.

Why do I need to enclose the variable in double quotes?

Spaces inside a variable used without quotes are treated as separators by Bash; "my file.txt" turns into two separate arguments and the command fails. Double quotes prevent this splitting. Practical rule: always use variables inside double quotes.

Why does my script give a permission error?

The file needs to be marked as executable; execution permission is granted with the chmod command. Alternatively, you can run the file by passing it directly as a parameter to the shell, in which case no permission is needed.

Summary

Bash is the common language of system administration and automation; it gets work done by chaining existing command-line tools. In this tutorial, we start with echo and progress through pipes, conditions, loops, and script parameters.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code