$
Learn Linux handbook
en
XP:0
Quest 99Arg-Master
+250 XP

Variables & Arguments ($1)

Launch Interactive Terminal for This Quest→No installation required • Runs fully in browser

Concept & Overview

Imagine creating a personalized welcome message for a website. You wouldn't want to write a separate script for every single customer's name! Instead, you write one script that takes a name as input when you run it.

- In bash scripts, variables like $1, $2, and so on hold the "arguments" or inputs you pass at the command line.
- E.g., running ./greet.sh Alice means $1 inside the script will automatically contain the text "Alice". Similarly, $# keeps track of how many inputs the user provided.

Let's build a dynamic script. Create greet.sh in your home directory with the shebang and the line echo "Hello, $1!". Make it executable and run ./greet.sh Alice to test it.

Command Syntax Reference

Command / SyntaxDescription
./greet.sh AliceExecute script with argument "Alice"

Verification Objectives

These conditions will be automatically verified when you run commands inside the interactive terminal simulator:

  • ○
    Create script file "greet.sh"
  • ○
    Use $1 inside greet.sh
  • ○
    Make greet.sh executable
  • ○
    Run the script with "Alice" argument

Ready to complete Quest 99?

Test your skills live in the browser terminal with an emulated Linux filesystem, real-time command evaluation, and instant step-by-step hints.