Script Basics for Shell and Bashs
Script basics cover the building blocks of a Bash script: the shebang line, variables, quoting rules, conditions and loops. Quoting decides how the shell splits and expands text, which makes it the most common source of beginner bugs. This unit marks the shift from typing single commands to writing reusable programs.
Stage: Bash Scripting · Part of the Shell and Bash roadmap · Last reviewed 19 November 2026
What to learn in Script Basics
- Start a script with a shebang, make it executable and run it
- Assign and expand variables, and explain why "$var" should usually be quoted
- Write if statements using [[ ]] tests for strings, numbers and files
- Loop over files and lists with for, while and case statements
- Capture command output with $( ) and use arithmetic with $(( ))
Script Basics interview questions
Why should you quote variable expansions in Bash?
Unquoted expansions undergo word splitting and globbing. A filename with a space becomes two arguments, and a value containing * can expand to a list of files. Writing "$file" keeps the value as one word and prevents many subtle bugs.
What is the difference between single and double quotes?
Single quotes keep every character literal, so $HOME stays as typed. Double quotes still allow variable expansion, command substitution and backslash escapes, but stop word splitting and globbing. Choose single quotes for fixed text and double quotes when you need a variable inside.
Where Script Basics fits in the Shell and Bash roadmap
Script Basics belongs to the Bash Scripting stage (beginner level), which takes about 12 hours. Automate.
Other units in this stage
Back to the full Shell and Bash roadmap