Linux/Raspberry Pi Script Basics

This document explains the basics of running scripts on Linux/Raspberry Pi.

Quick Answers

Why can’t I just type visualize_3d.sh?

You need ./ before the script name:

./visualize_3d.sh

Reason: Linux requires ./ to explicitly tell the system “run this script from the current directory”. This is a security feature - it prevents accidentally running scripts if someone puts a malicious file in your current directory.

Without ./, Linux looks for the script in your PATH (system directories like /usr/bin), not in the current folder.

What does chmod +x mean?

chmod +x makes a file executable (able to be run as a program).

What it means:

Why it’s needed:

When to use it:

Why *.sh instead of listing files?

The * is a wildcard (pattern matcher) that matches all files ending with .sh.

What *.sh means:

So chmod +x *.sh makes ALL these files executable at once:

Why use it? Instead of typing:

chmod +x visualize_3d.sh
chmod +x detect_pairs.sh
chmod +x setup_venv.sh
# ... (one line for each file)

You can do them all at once:

chmod +x *.sh

Step-by-Step Example

First Time Setup

  1. Make scripts executable (one-time setup):
    chmod +x *.sh
    

    This makes all .sh files executable (including all run scripts and setup_venv.sh).

  2. Run a program:
    ./visualize_3d.sh
    

    Note the ./ before the script name.

Every Time After That

Just run the script directly:

./visualize_3d.sh

You don’t need to run chmod +x again - the permission stays set.

Alternative: Run Without ./

If you really want to type just visualize_3d.sh (without ./), you can:

  1. Add current directory to PATH (not recommended for security):
    export PATH=$PATH:.
    visualize_3d.sh  # Now works without ./
    
  2. Or use the full path (works from anywhere):
    /home/user/GitHub/3D-Cam/visualize_3d.sh
    

But ./visualize_3d.sh is the standard, safe way to do it.

Summary