IntroToLinux

8. Advanced Environment Concepts

Variable Types:

Local Variables:

LOCAL_VAR="Only here"

Environment Variables:

export GLOBAL_VAR="Everywhere"

Special Variables:

echo "Last command status: $?"
echo "Shell process ID: $$"

Variable Manipulation:

# String length
VAR="Hello World"
echo ${#VAR}        # Output: 11

# Substring
echo ${VAR:0:5}     # Output: Hello
echo ${VAR:6}       # Output: World

# Default values
echo ${VAR:-"default"}      # Use VAR or "default" if empty
echo ${VAR:="default"}      # Set VAR to "default" if empty

Next: → Troubleshooting Common Issues
Previous: ← Practical Lab Environment Setup
Lesson Home: ↑ Lesson 3: History & Variables Course Home: ⌂ Introduction to Linux