Ready for Linux

Switch with confidence

Course overview · By Ready for Linux

Bash Scripting: Build Repeatable Linux Workflows

A script saves a sequence of commands so you can run a workflow again without retyping it. This course moves from a small saved script to arguments, decisions, and repeated work. The final project brings those pieces together in a reusable file-report script rather than asking you to memorize isolated syntax.

Before you begin

You should already know how to navigate directories, read and write files, quote filenames, and use basic command output. Complete the earlier file and text-processing courses when you need that foundation. Interactive scripting lessons require an account and an active pass that includes Bash Scripting.

What you will learn

  • Save commands in a file and run them with Bash.
  • Use variables and arguments to make a script reusable.
  • Use conditions to handle different inputs.
  • Repeat a task with a loop.
  • Inspect results and recover from mistakes.
  • Combine the course tools in a file-report project.

Read a filename from a script argument

# Save as show-file.sh
file="$1"
if [ -f "$file" ]; then
  cat "$file"
else
  printf '%s\n' "Choose an existing regular file"
fi

# Run with a file you created for practice
# bash show-file.sh notes.txt

The first argument is available as $1. The test checks whether it names a regular file, and cat displays it when the check succeeds. Quotes keep a filename containing spaces together as one argument. Run the saved script with bash show-file.sh notes.txt, substituting a practice filename. This example reads a file; it does not change it.

Course syllabus

13 lessons, from guided practice to an independent challenge.

  1. Save commands as a Bash script

    Save familiar commands and run them together with Bash. Course access required

  2. Store and quote a value

    Name a value once and expand it without splitting spaces. Course access required

  3. Understand the command environment

    Locate commands and pass a named value to a child Bash process. Course access required

  4. Pass information into a script

    Reuse the same saved commands with different input values. Course access required

  5. Signal success or failure

    Distinguish printed output from the status a script returns. Course access required

  6. Test whether a regular file exists

    Use test to turn a file question into an exit status. Course access required

  7. Choose an action with if and else

    Run one set of commands when a condition is true and another when it is false. Course access required

  8. Check inputs and report errors

    Reject incorrect argument counts without mixing error messages into useful output. Course access required

  9. Repeat work with a for loop

    Apply the same command to each supplied value without losing spaces. Course access required

  10. Capture an answer from a command

    Store a command's output in a variable and use it in a report. Course access required

  11. Name a reusable group of commands

    Define a function once and call it with different values. Course access required

  12. Diagnose a broken script

    Use syntax checks and execution tracing to repair a script, then verify varied inputs. Course access required

  13. Build a reusable file-report script

    Combine safe inputs, file tests, captured output and useful failure behavior. Course access required

Put it into practice

Start with the earlier shell course if this example feels unfamiliar. The scripting course introduces each part separately before combining them in its final project.

Continue learning

Linux Shell Essentials: Files and Directories · Explore the full syllabus

Reference: GNU Bash manual: shell scripts.