Bash Guide for Beginners

From LinuxReviews
Jump to navigationJump to search

Introduction

Why this guide?

The primary reason for writing this document is that a lot of readers feel the existing HOWTO to be too short and incomplete, while the Advanced Bash-Scripting Guide is too much of a reference work. There is nothing in between these two extremes. I also wrote this guide on the general principal that not enough free basic courses are available, though they should be.

This is a practical guide which, while not always being too serious, tries to give real-life instead of theoretical examples. I partly wrote it because I don't get excited with stripped down and over-simplified examples written by people who know what they are talking about, showing some really cool Bash feature so much out of its context that you cannot ever use it in practical circumstances. You can read that sort of stuff after finishing this book, which contains exercises and examples that will help you survive in the real world.

From my experience as UNIX/Linux user, system administrator and trainer, I know that people can have years of daily interaction with their systems, without having the slightest knowledge of task automation. Thus they often think that UNIX is not userfriendly, and even worse, they get the impression that it is slow and old-fashioned. This problem is another one that can be remedied by this guide.

Who should read this?

Everybody working on a UNIX or UNIX-like system who wants to make life easier on themselves, power users and sysadmins alike, can benefit from reading this book. Readers who already have a grasp of working the system using the command line will learn the ins and outs of shell scripting that ease execution of daily tasks. System administration relies a great deal on shell scripting; common tasks are often automated using simple scripts. This document is full of examples that will encourage you to write your own and that will inspire you to improve on existing scripts.

Prerequisites/not in this course:

  • You should be an experienced UNIX or Linux user, familiar with basic commands, man pages and documentation
  • Being able to use a text editor
  • Understand system boot and shutdown processes, init and initscripts
  • Create users and groups, set passwords
  • Permissions, special modes
  • Understand naming conventions for devices, partitioning, mounting/unmounting file systems
  • Adding/removing software on your system

You should refer to other guides if you haven't mastered one or more of these topics. Useful information can be found in your system documentation (man and info pages).

Versions & Revision History

These pages are based on Bash Guide for Beginners Revision 1.11 by Machtelt Garrels published by the The Linux Documentation Project in December 2008.

Copyright information


* Copyright (c) 2002-2007, Machtelt Garrels
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*     * Neither the name of the author, Machtelt Garrels, nor the
*       names of its contributors may be used to endorse or promote products
*       derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

What do you need?

bash, available from www.gnu.org/software/bash/. The Bash shell is available on nearly every Linux system, and can these days be found on a wide variety of UNIX systems.

Compiles easily if you need to make your own, tested on a wide variety of UNIX, Linux, MS Windows and other systems.

Conventions used in this document

The following typographic and usage conventions occur in this text:

Table 1. Typographic and usage conventions

Text type Meaning
"Quoted text" Quotes from people, quoted computer output.
terminal view
Literal computer input and output captured from the terminal, usually rendered with a light grey background.
command Name of a command that can be entered on the command line.
VARIABLE Name of a variable or pointer to content of a variable, as in $VARNAME.
option Option to a command, as in "the -a option to the ls command".
argument Argument to a command, as in "read man ls".
command options arguments Command synopsis or general usage, on a separated line.
filename Name of a file or directory, for example "Change to the /usr/bin directory."
Key Keys to hit on the keyboard, such as "type Q to quit".
Button Graphical button to click, like the OK button.
Menu ▸ Choice Choice to select from a graphical menu, for instance: "Select Help ▸ About Mozilla in your browser."
Terminology Important term or concept: "The Linux kernel is the heart of the system."
\ The backslash in a terminal view or command synopsis indicates an unfinished line. In other words, if you see a long command that is cut into multiple lines, \ means "Don't press ↵ Enter yet!"
See chapter 1 link to related subject within this guide.
The author Clickable link to an external web resource.

Organization of this document