Learn Bash Scripting
Automate repetitive terminal work with scripts you can trust.
Free to start. Built from a single prompt. No credit card.
Bash is the default shell on many Linux systems, and a Bash script is a text file of shell commands with variables, conditionals, loops and functions. Scripts glue together existing command-line tools to automate backups, deployments, file processing and server setup. Bash has quirks that other languages do not: whitespace and quoting matter a great deal, everything is a string by default, and success or failure is signaled by exit codes. Learning those rules is what turns fragile one-liners into reliable automation. Learnr builds a personalized Bash course from your prompt and teaches it through short, hands-on lessons.
How to learn Bash Scripting, step by step
- Be comfortable at the command line first. Scripts are just commands you already run, saved in a file. Make sure navigation, pipes, redirection and tools like grep, find and sort feel familiar before you start scripting.
- Write and run your first script. Start a file with #!/usr/bin/env bash, add a few commands, make it executable with chmod +x and run it with ./script.sh. Read arguments with $1, $2 and $@.
- Learn quoting before anything else. Always write "$var" in double quotes so filenames with spaces do not split into separate words. Know the difference between single quotes, double quotes and command substitution with $(...).
- Use conditionals and loops properly. Test with [[ ]] for strings and files, use (( )) for arithmetic, and handle options with case. Loop over files with for f in *.txt and read files line by line with while read -r.
- Handle errors with exit codes. Check $? or use if command; then, return meaningful exit codes from your scripts, and consider set -euo pipefail at the top while understanding what each flag changes. Print errors to stderr with >&2.
- Automate a real task and lint it. Write a backup script, a log cleaner or a bulk file renamer, then run ShellCheck on it and fix every warning. Brief daily Learnr lessons keep the syntax rules close at hand.
What you'll learn
- Write executable scripts with a shebang, variables and arguments
- Quote variables correctly and avoid word-splitting bugs
- Control flow with if, case, for and while using test expressions
- Use exit codes, pipes and redirection to handle errors
- Write reusable functions and lint scripts with ShellCheck
What's inside your Bash Scripting course
A sample path Learnr builds for Bash Scripting. Your real course adapts to your goal and level.
- 1. The shell, the shebang and running a script
- 2. Variables, arguments and quoting
- 3. Conditionals, tests and case statements
- 4. Loops over files, lines and arguments
- 5. Functions, exit codes and error handling
- 6. Real automation with text tools like grep, sed and awk
How long does it take to learn Bash Scripting?
With some terminal experience, you can write useful scripts in 1 to 3 weeks. Writing robust scripts that handle errors, arguments and odd filenames takes 1 to 3 months of practice. Knowing another programming language helps with logic but not with Bash quoting rules.
What you need before you start
Basic Linux or macOS command-line skills: moving between directories, managing files and using pipes. Access to a Bash shell on Linux, macOS or WSL.
Common mistakes to avoid
- Leaving variables unquoted, so a filename with a space breaks the script or deletes the wrong file. Quote every expansion unless you have a specific reason not to.
- Parsing the output of ls in loops. Use shell globs like for f in ./*.log or find with -print0 instead.
- Writing long programs in Bash that would be clearer in Python. Keep Bash for gluing commands together and switch languages when logic grows complex.
How Learnr builds your course
Type your topic
Tell Learnr you want to learn Bash Scripting, or get as specific as you like.
Get a personalized course
Learnr instantly builds a full Bash Scripting course tailored to your goal and skill level.
Learn and level up
Move through bite-sized lessons and interactive practice, earning XP and keeping your streak.
Bash Scripting questions, answered
What is the difference between Bash and the shell?
A shell is any program that interprets commands, such as sh, Bash, zsh or fish. Bash is one popular shell, and Bash scripts may use features not found in the basic POSIX sh.
Does macOS use Bash?
Newer macOS versions use zsh as the default interactive shell, but Bash is still available, and scripts with a Bash shebang run in Bash regardless of your login shell.
Should I learn Bash or Python for automation?
Learn both eventually. Bash is ideal for short scripts that chain command-line tools. Python is better for complex logic, data structures and anything that must run on many platforms.
Explore more courses
More programming and tech courses
- Learn Kubernetes
- Learn AWS
- Learn Cloud Computing
- Learn Data Structures and Algorithms
- Learn System Design
- Learn Node.js
- Learn Vue
- Learn Next.js
See all programming and tech courses
Ready to learn Bash Scripting?
Start your free, personalized Bash Scripting course in seconds. .