Decide what counts as a material in a shell project
Shell scripting has no physical supplies, so treat “materials” as the finite set of things a script is built from and tested against: one shell dialect, one plain-text script file, a short list of command-line utilities, sample input files, expected output, and a small set of reference pages. A text editor, terminal emulator and folder layout are tools or workspace choices; leave those to the sibling guides. Your goal here is to choose materials that are few enough to understand and real enough to test. A beginner script of 20-50 lines should need no more than one shell, 5-10 commands, 3-5 sample files and 1-2 reference sources. If your material list is longer, cut it before you write another line.
Choose one shell dialect before anything else
The shell dialect is the most important material because it decides which syntax is valid. POSIX sh is the smallest common language; Bash adds arrays, [[ ]] and set -o pipefail; Zsh adds different expansion and globbing behaviour. Pick one for your first 30-60 days and write it at the top of every script. Use #!/bin/sh for POSIX-only scripts or #!/usr/bin/env bash for Bash scripts. Check what you actually have with command -v bash, command -v sh and printf '%s\n' "$SHELL". Do not mix dialects in one 20-line script. If a tutorial uses [[ ]], do not run it under sh; if it uses #!/bin/sh, do not assume Bash arrays are available. On macOS, /bin/bash may be version 3.2, while Linux systems often ship Bash 5.x; that difference matters if you copy material that uses newer features.
Pick a plain-text script file and a naming convention
A shell script is a plain-text file, not a word-processor document. Choose UTF-8 text, Unix line endings (LF), and a name such as backup-photos.sh or check-disk.sh: lowercase, hyphens, no spaces, and a .sh ending for clarity. Keep the first script between 20 and 50 lines. Put the shebang on line 1, then a comment of 1-2 lines explaining the purpose. Aim for 80-100 characters per line so the script reads without horizontal scrolling. Set permissions deliberately: chmod 755 script.sh if it should be executable, or chmod 644 script.sh if you will run it with bash script.sh. Avoid tabs-versus-spaces arguments by choosing four spaces for indentation and using them consistently. If you download a script, run file script.sh; a result containing CRLF means Windows line endings and a likely bad interpreter error.
Select the commands and utilities your script will rely on
Commands are materials too. A beginner script should depend on 5-10 standard utilities, not 30. Good first choices are printf, test or [ ], grep, cut, sort, find, xargs, date, mkdir, cp, mv and rm. Prefer printf '%s\n' "$value" over echo when output must be predictable. Check each dependency with command -v grep before you rely on it. Keep the script to one or two external data-processing commands; a pipeline of five commands is harder to debug than a pipeline of two. If a command needs a version-specific option, record the minimum version in a comment, for example # needs GNU date -d. Do not choose a utility you cannot explain in one sentence. If you need a command only once, consider running it by hand rather than adding it to the script.
Gather sample data and expected output
You cannot test materials you do not have. Create 3-5 sample files: one normal file of 5-20 lines, one empty file, one file with spaces in its name, and one deliberately malformed file. Keep each sample under 1 MB and the whole set under 10 MB so tests run in 0.5-2 seconds. Write the expected output in a second plain-text file, or as 3-5 commented lines at the bottom of the script. Include one case with 100 files in a directory if your script loops over files; include one case with a single file. Use the same data for every run so you can tell whether a change fixed anything. If real data is sensitive, replace names and numbers with fake values before saving it; never commit passwords, tokens or personal data as sample material.
Choose reference material and documentation
Keep reference material small and authoritative: the manual page for each command (man grep), the command’s --help output, and one shell-language reference for your chosen dialect. Two sources are enough for a first script. Spend 10-15 minutes reading the OPTIONS and EXIT STATUS sections of each man page you use. Write down 3-5 facts you will rely on, such as whether grep returns 1 when no line matches or whether find prints paths relative to the starting directory. Avoid copying from undated forum posts unless you can confirm the behaviour with a 5-line test script. If a reference example is longer than 15 lines, reduce it to the smallest command that proves the point.
Set material limits: permissions, environment and portability
Decide the boundaries of your materials before they sprawl. Target one operating system family and one shell for your first script; testing on two systems is a later step. Use absolute paths such as $HOME/scripts or a documented relative path, not an unexplained cd. Set a default umask of 022 and choose file modes of 644 for data and 755 for executable scripts. Limit environment variables to the 3-6 you actually need, and quote them: "$HOME", "$USER", "$PATH". If your script creates temporary files, put them under a directory you control and clean up files older than 1 day. Record the target in a comment: # target: Linux, bash 5.x. That single line prevents most portability confusion.
Diagnose a common materials failure: works here, fails there
Symptoms: the script runs on your machine but prints command not found, Permission denied or bad interpreter on another. Likely causes: the shebang points to a shell that is not installed; the script depends on a utility outside the default PATH; the file has CRLF line endings; or the executable bit is missing. The fix is to check materials in order. Run file script.sh to catch CRLF, command -v bash and command -v grep to confirm dependencies, bash -n script.sh to catch syntax errors, and ls -l script.sh to confirm mode 755. If the shebang is wrong, change line 1 rather than running the script with a different shell by accident. If a utility is missing, either install it deliberately or replace it with a standard alternative; do not add five fallback commands to a 20-line beginner script.
FAQ
Do I need to install a different shell to learn shell scripting?
No. Start with the shell already on your system, usually sh, Bash or Zsh, and confirm it with printf '%s\n' "$SHELL". Install another shell only when a specific exercise requires it and you can state the reason in one sentence.
How much sample data should a beginner script use?
Use 3-5 files, each 5-20 lines and under 1 MB, plus one empty case and one malformed case. That is enough to test normal, empty and broken input without making a 0.5-2 second test run slow.
Is it okay to copy commands from examples?
Yes, if you test each command in a 5-line script and can explain what it reads, what it writes and what exit status it returns. Copying a 50-line example you cannot debug is not a material choice; it is a future failure.