IntroToLinux

2. Creating Your First Script

Script File Structure:

#!/bin/bash
# This is a comment
# Script: hello-world.sh
# Purpose: Demonstrate basic script structure

echo "Hello, World!"
echo "This is my first shell script"

The Shebang Line:

Making Scripts Executable:

# Create script file
nano hello-world.sh

# Make executable
chmod +x hello-world.sh

# Run script
./hello-world.sh

# Or run without making executable
bash hello-world.sh

Script Location and PATH:

# Run from current directory
./script.sh

# Make available system-wide
sudo cp script.sh /usr/local/bin/
sudo chmod +x /usr/local/bin/script.sh

# Now can run from anywhere
script.sh

Next: → Comments And Documentation
Previous: ← Introduction To Shell Scripting
Lesson Home: ↑ Lesson 8: Scripting Course Home: ⌂ Introduction to Linux