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:
chmod= “change mode” (file permissions)+x= “add execute permission”
Why it’s needed:
- Linux doesn’t automatically make files executable for security
- New files are created without execute permission
- You must explicitly give permission to run scripts
When to use it:
- Only needed once per file (the first time)
- After that, you can run the script anytime with
./script.sh
Why *.sh instead of listing files?
The * is a wildcard (pattern matcher) that matches all files ending with .sh.
What *.sh means:
*= matches any filename.sh= ends with “.sh”
So chmod +x *.sh makes ALL these files executable at once:
visualize_3d.shdetect_pairs.shcapture_raspi.shsetup_venv.sh- etc.
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
- Make scripts executable (one-time setup):
chmod +x *.shThis makes all
.shfiles executable (including all run scripts and setup_venv.sh). - Run a program:
./visualize_3d.shNote 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:
- Add current directory to PATH (not recommended for security):
export PATH=$PATH:. visualize_3d.sh # Now works without ./ - 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
./= required to run scripts in current directorychmod +x= needed once to make files executable*= wildcard to match multiple files- Only needed once = after
chmod +x, you can run scripts anytime