The Bash Guide

by lhunath (thanks)

This guide is an introduction to basic and advanced concepts of the bash shell.

It teaches both newcomers and long-time users the best, safest and most robust ways of writing powerful bash scripts as well as making efficient and speedy interactive use of the shell.

This guide has gone through several iterations and is the result of a severe lack of consistent, clear and reliable language on the topic on the rest of the Internet as well as the public library or book stores.

Chapters

  1. Inceptiondraft: What is bash, and where does it live?

    An introduction to bash, installing and starting it, the terminal, the keyboard and the display, programs, processes and how their flow of information is connected.

  2. Commands And Argumentsdrafting: How do I give bash instructions?

    About what a command is, how bash takes commands, interactive mode and scripts, command syntax, searching commands and programs by name, arguments and word splitting, input and output redirection and the command environment.

  3. Variables And Expansionstodo: How do I store and work with data?

    Bash parameters and variables, environment variables, special parameters, array parameters, expanding parameters, expansion operators, command substitution and process substitution, pathname expansion, tilde expansion and brace expansion, quoting and word splitting.

  4. Tests And Conditionalstodo: Different commands for different data.

    Exit codes, success and failure, testing files, strings and numbers, handling different conditions, conditional operators and conditional compound commands.

  5. Loops And Functionstodo: Avoid repeating yourself.

    Iterating commands using for loops, while and until loops, select statements and grouping them in functions.

  6. Asynchronous Commandstodo: Doing work in the background and managing jobs.

    About jobs, asynchronous commands, job control, process identifiers and signals, process management, inter-process communications.

  7. Colors And Terminal Commandstodo: Advanced control over the terminal display.

    Terminals and terminal sequences, terminal identifiers, terminfo and terminal capabilities, outputting colors, moving the cursor and querying the terminal's state.

  8. Customizing The Prompttodo: Changing the look and feel of the interactive shell.

    Prompting, prompt commands and the DEBUG signal, readline, bind and input modes and hotkeys, programmatic command completion.

  9. Advanced Topicstodo: About syntax sugar, specific use cases and shell tricks.
  10. Recommendations And Pitfallstodo: How to do things well and how to do things very, very badly.
  11. Noteworthy External Toolstodo: Bash is limited, but augmented by a powerful toolset.

Authorship

The primary author and maintainer of this guide is lhunath (Maarten Billemont).

This guide is open source, licensed under Creative Commons Attribution-ShareAlike 4.0 International License (CC-BY-SA). The source code is available at GitHub and you are welcome to fork it, modify it and contribute changes back to this document as pull requests.

For advice, comments, suggestions, corrections or recommendations, contact lhunath, file an issue or visit the freenode.org #bash community on IRC.

Creative Commons License

Fork me on GitHub