1. Introduction to Scripting
Pre-requisite: Before you start scripting it is advised that you memorise the basic commands by heart and mind.
Note: Here we will cover shell scripting which we do in Unix Operating Systems.
Scripting is running/executing some sets of commands as per our requirement. It is mostly used for automating some tasks. Such as:
- Executing same sets of commands for a variable with multiple values such as for a variable users with multiple values: "user1 user2 user3"
With executing same sets of commands means - Commands are being executed in some loop. For this we will learn "for loop" and "while loop".
- Executing some commands based on some conditions. For example: if file xyz exists check its contents and if not exist then create a file xyz.
With executing some commands based on some condition means - Commands are executed only if some conditions meet. For this we will learn "if condition".
Before we proceed any further you must know what is variable and value.
- variable is something that keep changing its value. Such as filename.
- value is something that you define for some variable. such as "file1, file2, file3".
How to deifine value to a variable:
Syntax:
variable="value"
Example:
filename="Winner-List.txt"
How to view/display value of a variable:
Syntax:
echo "$variable"
Example:
echo "$filename"
Practicle
[user1@localhost Folder]$ filename="Winner-List.txt"
[user1@localhost Folder]$ echo $filename
Winner-List.txt
[user1@localhost Folder]$ filepath="/home/user1/Folder/Winner-List.txt"
[user1@localhost Folder]$ echo "$filepath"
/home/user1/Folder/Winner-List.txt
‹
›