Course Overview

/

Bash-Strings, Integers & Variables

Bash

Bash (short for Bourne-Again Shell) is the command line interface and scripting language used by Unix and Linux operating systems. Because of this, there is no need to install anything if you are working on these operating systems.

Starting our first script

Our first script will be similar to our first python script. This is so that you can see the differences and similarities between the two scripting languages. The overarching concepts are the same, however syntax will vary.

As with Python, strings can be encapsulated in both singles quotes (‘) or double quotes (“) whereas integers do not require this.

1st Bash Script

The first bash script created is:

This will use the Bash echo function to output the strings Hello World, and “this is a sentence on multiple lines” to the terminal. The echo command is the keyword used to output values to the terminal.

Bash has the ability to conduct mathematical calculations as part of the script but these must use the $ character to reference a parameter or variable. The mathematical equation is calculated in the $(()) syntax and the $ character represents that the output is what will be echo’d to the terminal.

This is very similar with our variables. These can be defined with a simple x=2 statement but to output the values to the terminal we use the $ character and pass the name of the variable.