shlogg · Early preview
Osagie Anolu @nolunchbreaks

Basic Shell Scripting With Bash

Bash scripts use variables to store & manipulate data. Examples: string vars ("John Doe"), int vars (age=30), array vars (fruits=("apple" "banana")), assoc arrays (person["name"]="John Doe") & more!

Basic Syntax and Variables

  
  
  Variables


name="John"
echo $name    # Basic output
echo "$name"  # Recommended way (with quotes)
echo "${name}"  # Most explicit way

    
    

    
    




  
  
  String Quotes

Double quotes allow variable expansion: "Hello $name"
Single quotes preserve literal text: 'Hello $name'


  
  
  Shell Execution


echo "Current directory: $(pwd)"   # Modern syntax
echo "Current directory: `pwd`"    # Legacy syntax

    
    

    
    




  
  
  Control Flow

  
  
  Conditional Execution


git commit && git push             # Run second command only if f...