Personal tools
You are here: Home Docs Help! Reference Manuals Bash Guide for Beginners

Bash Guide for Beginners

This Reference Manual applies to: All
This Reference Manual is intended for: Beginner

Version 1.10 Last updated 20080606 Edition

All content on one page (useful for printing, presentation mode etc.)

  1. Bash and Bash scripts
    1. Common shell programs
      1. General shell functions
      2. Shell types
    2. Advantages of the Bourne Again SHell
      1. Bash is the GNU shell
      2. Features only found in bash
        1. Invocation
        2. Bash startup files
          1. Invoked as an interactive login shell, or with `--login'
          2. Invoked as an interactive non-login shell
          3. Invoked non-interactively
          4. Invoked with the sh command
          5. POSIX mode
          6. Invoked remotely
          7. Invoked when UID is not equal to EUID
        3. Interactive shells
          1. What is an interactive shell?
          2. Is this shell interactive?
          3. Interactive shell behavior
          4. Conditionals
          5. Shell arithmetic
          6. Aliases
          7. Arrays
          8. Directory stack
          9. The prompt
          10. The restricted shell
    3. Executing commands
      1. General
      2. Shell built-in commands
      3. Executing programs from a script
    4. Building blocks
      1. Shell building blocks
        1. Shell syntax
        2. Shell commands
        3. Shell functions
        4. Shell parameters
        5. Shell expansions
        6. Redirections
        7. Executing commands
        8. Shell scripts
    5. Developing good scripts
      1. Properties of good scripts
      2. Structure
      3. Terminology
      4. A word on order and logic
      5. An example Bash script: mysystem.sh
      6. Example init script
    6. Summary
    7. Exercises
  2. Writing and debugging scripts
    1. Creating and running a script
      1. Writing and naming
      2. script1.sh
      3. Executing the script
    2. Script basics
      1. Which shell will run the script?
      2. Adding comments
    3. Debugging Bash scripts
      1. Debugging on the entire script
      2. Debugging on part(s) of the script
    4. Summary
    5. Exercises
  3. The Bash environment
    1. Shell initialization files
      1. System-wide configuration files
        1. /etc/profile
        2. /etc/bashrc
      2. Individual user configuration files
        1. ~/.bash_profile
        2. ~/.bash_login
        3. ~/.profile
        4. ~/.bashrc
        5. ~/.bash_logout
      3. Changing shell configuration files
    2. Variables
      1. Types of variables
        1. Global variables
        2. Local variables
        3. Variables by content
      2. Creating variables
      3. Exporting variables
      4. Reserved variables
        1. Bourne shell reserved variables
        2. Bash reserved variables
      5. Special parameters
      6. Script recycling with variables
    3. Quoting characters
      1. Why?
      2. Escape characters
      3. Single quotes
      4. Double quotes
      5. ANSI-C quoting
      6. Locales
    4. Shell expansion
      1. General
      2. Brace expansion
      3. Tilde expansion
      4. Shell parameter and variable expansion
      5. Command substitution
      6. Arithmetic expansion
      7. Process substitution
      8. Word splitting
      9. File name expansion
    5. Aliases
      1. What are aliases?
      2. Creating and removing aliases
    6. More Bash options
      1. Displaying options
      2. Changing options
    7. Summary
    8. Exercises
  4. Regular expressions
    1. Regular expressions
      1. What are regular expressions?
      2. Regular expression metacharacters
      3. Basic versus extended regular expressions
    2. Examples using grep
      1. What is grep?
      2. Grep and regular expressions
        1. Line and word anchors
        2. Character classes
        3. Wildcards
    3. Pattern matching using Bash features
      1. Character ranges
      2. Character classes
    4. Summary
    5. Exercises
  5. The GNU sed stream editor
    1. Introduction
      1. What is sed?
      2. sed commands
    2. Interactive editing
      1. Printing lines containing a pattern
      2. Deleting lines of input containing a pattern
      3. Ranges of lines
      4. Find and replace with sed
    3. Non-interactive editing
      1. Reading sed commands from a file
      2. Writing output files
    4. Summary
    5. Exercises
  6. The GNU awk programming language
    1. Getting started with gawk
      1. What is gawk?
      2. Gawk commands
    2. The print program
      1. Printing selected fields
      2. Formatting fields
      3. The print command and regular expressions
      4. Special patterns
      5. Gawk scripts
    3. Gawk variables
      1. The input field separator
      2. The output separators
        1. The output field separator
        2. The output record separator
      3. The number of records
      4. User defined variables
      5. More examples
      6. The printf program
    4. Summary
    5. Exercises
  7. Conditional statements
    1. Introduction to if
      1. General
        1. Expressions used with if
        2. Commands following the then statement
        3. General
        4. Checking shell options
      2. Simple applications of if
        1. Testing exit status
        2. Numeric comparisons
        3. String comparisons
    2. More advanced if usage
      1. if/then/else constructs
        1. Dummy example
        2. Checking command line arguments
        3. Testing the number of arguments
        4. Testing that a file exists
      2. if/then/elif/else constructs
        1. General
        2. Example
      3. Nested if statements
      4. Boolean operations
      5. Using the exit statement and if
    3. Using case statements
      1. Simplified conditions
      2. Initscript example
    4. Summary
    5. Exercises
  8. Writing interactive scripts
    1. Displaying user messages
      1. Interactive or not?
      2. Using the echo built-in command
    2. Catching user input
      1. Using the read built-in command
      2. Prompting for user input
      3. Redirection and file descriptors
        1. General
        2. Redirection of errors
      4. File input and output
        1. Using /dev/fd
        2. Read and exec
          1. Assigning file descriptors to files
          2. Read in scripts
        3. Closing file descriptors
        4. Here documents
    3. Summary
    4. Exercises
  9. Repetitive tasks
    1. The for loop
      1. How does it work?
      2. Examples
        1. Using command substitution for specifying LIST items
        2. Using the content of a variable to specify LIST items
    2. The while loop
      1. What is it?
      2. Examples
        1. Simple example using while
        2. Nested while loops
        3. Using keyboard input to control the while loop
        4. Calculating an average
    3. The until loop
      1. What is it?
      2. Example
    4. I/O redirection and loops
      1. Input redirection
      2. Output redirection
    5. Break and continue
      1. The break built-in
      2. The continue built-in
      3. Examples
    6. Making menus with the select built-in
      1. General
        1. Use of select
        2. Examples
      2. Submenus
    7. The shift built-in
      1. What does it do?
      2. Examples
    8. Summary
    9. Exercises
  10. More on variables
    1. Types of variables
      1. General assignment of values
      2. Using the declare built-in
      3. Constants
    2. Array variables
      1. Creating arrays
      2. Dereferencing the variables in an array
      3. Deleting array variables
      4. Examples of arrays
    3. Operations on variables
      1. Arithmetic on variables
      2. Length of a variable
      3. Transformations of variables
        1. Substitution
        2. Removing substrings
        3. Replacing parts of variable names
    4. Summary
    5. Exercises
  11. Functions
    1. Introduction
      1. What are functions?
      2. Function syntax
      3. Positional parameters in functions
      4. Displaying functions
    2. Examples of functions in scripts
      1. Recycling
      2. Setting the path
      3. Remote backups
    3. Summary
    4. Exercises
  12. Catching signals
    1. Signals
      1. Introduction
        1. Finding the signal man page
        2. Signals to your Bash shell
        3. Sending signals using the shell
      2. Usage of signals with kill
    2. Traps
      1. General
      2. How Bash interprets traps
      3. More examples
        1. Detecting when a variable is used
        2. Removing rubbish upon exit
    3. Summary
    4. Exercises
  13. Appendix - Shell Features
    1. Common features
    2. Differing features
  14. Introduction
    1. Why this guide?
    2. Who should read this book?
    3. New versions, translations and availability
    4. Revision History
    5. Contributions
    6. Feedback
    7. Copyright information
    8. What do you need?
    9. Conventions used in this document
    10. Organization of this document
Broadband Deals
Compare the best broadband deals available in the UK from all the leading Internet Service Providers including BT, Sky and Virgin Media.
IT Support Manchester
For IT support, Manchester based MailSure will provide technical support for your IT needs or take control of your IT requirements at any stage in your business development.
IT Support Bristol
IT Services and IT Support provider based in Bristol. Computer maintenance with server support as standard.
Mobile Broadband Deals
Compare the cheapest mobile broadband deals on Mobile Broadband Genie, the independent UK price comparison website.
Project Planning Software
Atlantic Global offers full solutions of project management software, including project planning software, timesheets and more
City Leased Lines
Dedicated 100Mbit fibre optic Internet and Cloud outsourcing in the City of London, call now on 020 7096 9004 or email sales@metro-tek.com
IT Support
For The Best IT Support In London Make Our IT Department Your IT Department. Microsoft Gold Certified Partner.
IT Support London
Efficent IT Support & Hosted Services for SME businesses in and around greater London.
Reliable Web Hosting
Affordable Web Hosting with one click installs for Joomla, Moodle, Wordpress and more!
Data Recovery
Professional data recovery services