๐ป Today in #comptia #Linux+ class:
โ The Bash shell is commonly used ๐๐๐๐๐๐๐๐๐๐๐๐๐: It lets you enter and edit commands, then executes them when you press the Enter/Return key.
โญ However, The Bash shell can also be run ๐๐๐-๐๐๐๐๐๐๐๐๐๐๐๐๐ from a script, making the shell require no human interaction. Interactive behavior and scripted behavior should be identical. Therefore anything that can be done at the command line can be put in a script file for reuse.
โ Scripting is a versatile tool in the field of computing and automation, serving various purposes. Today, we'll delve into the fundamentals of bash scripting, ๐๐๐๐๐๐๐๐ ๐๐ ๐๐๐๐๐, ๐๐๐๐๐๐๐๐๐๐ (๐๐๐๐๐๐๐๐๐๐), ๐๐๐ ๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐.
๐๐ซ๐ข๐ญ๐ ๐ ๐๐๐ฌ๐ก ๐ฌ๐๐ซ๐ข๐ฉ๐ญ ๐ญ๐ก๐๐ญ ๐ฎ๐ฉ๐จ๐ง ๐๐ฑ๐๐๐ฎ๐ญ๐ข๐ง๐ ๐ฐ๐ข๐ฅ๐ฅ:
1๏ธโฃ Ask the user to โEnter the first number:โ
2๏ธโฃ Then, upon user entering the first number, will ask: โEnter the second number:โ
3๏ธโฃ It then assigns the command line arguments to variables num1 and num2.
4๏ธโฃ The script performs addition, subtraction, multiplication, and division on these numbers and displays the results.
5๏ธโฃ It also handles the case where division by zero is attempted.
๐ด Create a new file called exercise.sh using nano
$ nano exercise.sh
- The first line of the script must start with the character sequence #!, referred to as shebang1. The shebang instructs the operating system to run /bin/bash, the Bash shell, passing it the script's path as an
argument.
๐ด Then, I start writing the script as per picture. (Approaching the finale, I add a touch of fun to it!)
๐ด Make the script executable by running sudo chmod +x exercise.sh
๐ด Execute the exercise.sh script from the command line using:
$ ./exercise.sh (most commonly used, and recommended)
Thank you Dr. Harjinthar Singh
#cybersecurity #selfchallenge #100cyberdays #cybersecuritymalaysia #linux #scriptingย