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
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
Another example of this is the if statement. There must be a space after the if.
if [[ a > b ]]; then
if[[ a > b ]]; then
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
#variableB is set to 1 notce the $