Arithmetic operators

Arithmetic operators allow you to perform mathematical operations in Shell Script. Here are some of the most common arithmetic operators in Shell Script:

“+” (addition)
“-” (subtraction)
“*” (multiplication)
“/” (division)
“%” (modulo, which returns the remainder of a division)

Here is an example of how to use arithmetic operators in Shell Script to calculate the sum of two numbers:

number 1=5
number 2=10
sum=$((number1 + number2))
echo “The sum of $number1 and $number2 is $sum”

Variables

Variables are used in Shell Script to store temporary or permanent data such as strings or numbers. They can be defined and used in a variety of ways in a shell script.

To define a variable in a shell script, simply assign a value to it. Here’s an example of how to define a variable called “name”:

name=”Yan”

To use the variable in a later command in the script, simply use the variable name with a dollar sign ($) before it. Here is an example of how to print the value of the variable “name” using the “echo” command:

echo “Hello, $name!”

Types of shell commands

We can find internal and external commands.
Comandos internos fazem parte do próprio shell.
Comandos externos são binários armazenados nos diretórios /sbin, /usr/sbin, /usr/bin, /bin ou /usr/local/bin.

Text typed into the terminal can be divided into three parts, the command, options starting with or, and the argument. These divisions must be separated by spaces.

As an example, let’s list the files inside the tmp folder, using a long listing.

ls -l /tmp/