Elementary Overview
Bash is both a command shell and a scripting language. You can type commands interactively into a terminal, or you can save a sequence of commands in a text file and run that file as a script. A Bash script is useful when you want the computer to repeat a procedure consistently instead of relying on you to type every command by hand.
This first Bash lesson stays deliberately narrow. You will learn what a shell is, what makes Bash different from the terminal window itself, how a script file works, what a shebang does, why executable permission matters, and why ./script.sh is different from simply typing a command name. Later Bash lessons will slow down and focus separately on commands and paths, variables, quoting, pipes, redirection, conditionals, loops, functions, arguments, exit codes, text-processing tools, permissions, processes, environment variables, scheduling, SSH automation, logging, and safe error handling.
What You Should Learn
- What a shell does and where Bash fits.
- The difference between an interactive command and a saved shell script.
- How to create a first Bash script.
- What the
#!shebang line means. - How to run a script with
bash script.sh. - How to make a script executable with
chmod +x. - Why
./script.shspecifies a path to the current directory. - Why the shell searches
PATHwhen you type a command name without a slash. - How to read the first common Bash execution errors without guessing.
What A Shell Is
A shell is a program that reads commands and starts other programs. Bash stands for Bourne Again Shell. It grew out of the Unix shell tradition and remains one of the most widely encountered shells on Linux systems, servers, containers, development environments, and infrastructure tooling.
The terminal window is not Bash itself. A terminal application gives you a text interface. Inside that terminal, a shell such as Bash, Zsh, or another command interpreter reads what you type. That distinction becomes important when a script behaves differently under bash than it does under sh or another shell.
When the shell launches another program, the operating system participates in the process-creation and execution path. The earlier BitcoinVersus.Tech explainer What Are fork() and exec()? provides useful background on how Unix-like systems create and launch programs beneath the command line.

Interactive Commands Versus Scripts
If you type a command directly at a Bash prompt, Bash reads and executes it interactively. For example:
pwd
ls
echo "Hello"
A script stores commands in a file so the same sequence can be run again. The GNU Bash manual defines a shell script as a text file containing shell commands. That simple idea is the foundation of automation: commands that work interactively can often be organized into a repeatable script.
Create Your First Script
Create a file named hello.sh in a working directory. Use any plain-text editor you are comfortable with. If you are new to code editors, the BitcoinVersus.Tech lesson What Is Syntax Highlighting? explains why editors visually distinguish commands, strings, comments, and other syntax.
#!/usr/bin/env bash
echo "Hello from Bash"
The second line runs the Bash builtin echo, which writes text to standard output. The first line is more unusual. It begins with the two characters #!, commonly called a shebang.
What The Shebang Does
When a script is executed directly, the shebang tells the operating system which interpreter should handle the file. In this example:
#!/usr/bin/env bash
env searches the current environment’s PATH for a program named bash. Another common form is #!/bin/bash, which names a specific path directly. Which form is appropriate depends on the environment and deployment requirements. The important beginner rule is simpler: the shebang identifies the intended interpreter when the script is executed as a program.
If you explicitly run bash hello.sh, you are already choosing Bash on the command line, so Bash can read the file even if it is not marked executable. Direct execution through ./hello.sh is different because the file itself is being launched as a program.
bash script.sh.Run The Script With Bash
The most direct beginner test is:
bash hello.sh
This starts Bash and gives the script file to Bash as input. The file needs to be readable, but it does not need its executable permission bit set just to be read this way.
If the command works, you have already proved several things: Bash exists, the shell can find the Bash executable, the file is readable, and the script syntax is valid enough for Bash to execute it.
Make The Script Executable
To launch the file directly as a program, add executable permission:
chmod +x hello.sh
Then run it with a path:
./hello.sh
chmod +x changes the file’s mode so the operating system can treat it as executable for the applicable permission classes. Permissions deserve their own later lesson; for now, remember the practical sequence: create the script, add a shebang, make the file executable, then launch it with a path.
Why ./ Matters
The characters ./ are a path. A single dot means the current directory, so ./hello.sh means “execute the file named hello.sh from this directory.”
If you type only hello.sh, Bash normally treats that as a command name and searches the directories listed in the PATH environment variable. The current directory is commonly not included in PATH by default, which is why a local script may work with ./hello.sh but not with hello.sh.
For a deeper explanation, read What Is the PATH Environment Variable?. Later in this Bash track, commands and paths will get a dedicated lesson rather than being overloaded into this introduction.
Comments And Blank Lines
In Bash, a line beginning with # is normally a comment. Comments are ignored as shell commands and are useful for explaining why a script exists or what a section is doing.
#!/usr/bin/env bash
# Print a simple greeting.
echo "Hello from Bash"
The shebang is a special first-line case recognized by the operating system when the file is executed. Blank lines are also useful because they visually separate logical sections without changing normal execution.
Read Errors In A Fixed Order
bash: command not found: verify Bash is installed and discoverable throughPATH.No such file or directory: verify your current directory, the filename, and the path you typed. Also inspect the shebang if direct execution fails unexpectedly.Permission deniedwith./script.sh: inspect the file’s execute permission.- Works with
bash script.shbut not./script.sh: check executable permission and the shebang. - Works in Bash but fails under
sh: the script may use Bash-specific syntax. Run it with the interpreter it was written for instead of assuming every shell is interchangeable.
This habit matters more than memorizing one error message. Start with the command you typed, the path, permissions, interpreter, and first useful diagnostic. Avoid changing several unrelated things at once.
Mini Lab
- Create a directory named
bash_laband enter it. - Create
hello.shcontaining a Bash shebang and oneechocommand. - Run it with
bash hello.sh. - Run
ls -l hello.shand inspect the permissions. - Add executable permission with
chmod +x hello.sh. - Run it with
./hello.sh. - Remove the executable bit and observe what changes for direct execution.
- Restore executable permission.
- Temporarily misspell the filename and read the exact error instead of guessing.
- Commit the working script to a small repository if you are practicing Git and GitHub.
Common Beginner Mistakes
- Confusing the terminal with Bash: the terminal hosts a shell; Bash is one possible shell.
- Assuming every
.shfile is Bash: the extension does not determine the interpreter by itself. - Forgetting the shebang: direct execution needs a clear interpreter path if the operating system is expected to choose the interpreter.
- Forgetting executable permission:
bash script.shand./script.share not identical execution paths. - Typing only a local filename: command lookup uses
PATH;./explicitly names the current directory. - Running a Bash script with
sh: Bash-specific syntax is not guaranteed to work under another shell. - Editing several things after one error: change one variable at a time so you know what fixed the problem.
Exercises
- Explain the difference between a terminal and a shell.
- Create a two-line Bash script that prints your chosen message.
- Run the script once with
bash filenameand once through direct execution. - Use
ls -lbefore and afterchmod +xand identify the changed permission bit. - Explain what
./means in./hello.sh. - Explain why typing only
hello.shmay produce “command not found.” - Change the shebang to an invalid path, attempt direct execution, record the error, and restore the correct shebang.
- Write one comment in a script that explains intent rather than repeating the command.
Knowledge Check + Answers
- What is Bash? A Unix-style command shell and scripting language.
- Is a terminal window the same thing as Bash? No. A terminal provides the text interface in which a shell such as Bash can run.
- What is a Bash script? A text file containing commands intended to be read and executed by Bash.
- What does a shebang do? It identifies the interpreter intended to execute the file when the script is launched directly.
- Does
bash hello.shrequire the file to have its executable bit set? No. Bash reads the file as input. - What does
chmod +x hello.shdo? It adds executable permission according to the applicable file mode classes. - What does
./hello.shmean? Executehello.shusing the path to the current directory. - Why might
hello.shalone fail? The shell searchesPATH, and the current directory may not be in that search path. - Should a Bash-specific script automatically be run with
sh? No. Use the interpreter the script was written and tested for.
Primary References
- GNU Bash Reference Manual
- GNU Bash Reference Manual — Shell Scripts
- GNU Coreutils — chmod
- BitcoinVersus.Tech — What Is the PATH Environment Variable?
- BitcoinVersus.Tech — What Are fork() and exec()?
Elementary Review
A Bash script is simply a text file containing shell commands, but execution details matter. The shebang identifies the intended interpreter for direct execution. bash script.sh explicitly starts Bash and asks it to read the file. chmod +x makes direct execution possible, and ./ tells the shell exactly where the local script is. Once those mechanics make sense, later Bash syntax becomes much easier to troubleshoot.
The next canonical Bash lesson is OSBash.002: Commands and Paths, where command lookup, absolute paths, relative paths, PATH, current directories, and executable discovery can be studied in detail.
Editor’s Note
The featured image is an original 1200×630 BitcoinVersus.Tech photograph created specifically for OSBash.001 and is not reused in the body. The lesson uses a separate original 1200×675 body photograph. The three YouTube videos use responsive native Gutenberg 16:9 embed blocks, and the social item uses a responsive native Gutenberg embed. Ordinary lesson prose is not placed inside bordered, shaded, card, callout, panel, or fixed-width text boxes.
BitcoinVersus.Tech content is provided for informational and educational purposes.

Leave a Reply