BASH – Beginners Guide for Quick Learning

I have been learning BASH (Bourne Again Shell) over the few days and I want to share with you my experience so you don’t have to expose your poor computer to any profanity.

Before beginning this tutorial you should have some experience with

  • The basics of using a linux command line terminal (cd and ls)
  • Using a command line editor such as emacs, vim, and pico
  • Basic knowledge of some other programming language

Whitespace Matters

So the first thing I noticed is that BASH is very white space dependent. For example when you initialize a variable do not add spaces on the sides of the equal sign.

VARIABLE=VALUE

not

VARIABLE = VALUE

Another example of this is the if statement. There must be a space after the if.

if [[ a > b ]]; then
#some action
fi

not


if[[ a > b ]]; then
#some action
fi

I don’t think it matters if you have multiple spaces as long as you have one space where it is required.

The Basics of Accessing and Setting Variables

Setting a variable and accessing a variable is a little strange especially if you are coming from a php programming background. To set a variable you just write the variable name and the equal sign. To access a variable you have to use the $ sign.

#variableA is set to 1
varableA=1

#variableB is set to 1 notce the $
variableB=$variableA

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *