Basic Scripting | Cyber Security Tutorial - Learn with VOKS
Advance AI Bootstrap C C++ Computer Vision Content Writing CSS Cyber Security Data Analysis Deep Learning Email Marketing Excel Figma HTML Java Script Machine Learning MySQLi Node JS PHP Power Bi Python Python for AI Python for Analysis React React Native SEO SMM SQL
Back Next

Basic Scripting

Learn this topic step-by-step with VOKS Tutorials.

What Is a Script?

A script is:

A text file that contains a list of commands.

When you run the script, the system executes each command in order.

Think of it like:

Instead of telling someone step-by-step what to do every time, you write instructions once and hand them over whenever needed.

Why Use Scripting?

Scripting helps you:

  • Automate repetitive tasks
  • Save time
  • Reduce human error
  • Perform complex operations easily
  • Run tasks on multiple files at once

Example tasks:

  • Backing up files
  • Renaming many files
  • Starting multiple programs
  • Cleaning temporary files

Basic Bash Script (Linux/macOS)

On Linux or macOS, scripting is often done using Bash.

Create a file called:

myscript.sh

Example:

#!/bin/bash

echo "Hello, world!"
echo "This is my first script."

mkdir TestFolder
cd TestFolder
touch example.txt

echo "Script finished."

Explanation:

  • #!/bin/bash tells the system to use Bash.
  • echo prints text.
  • mkdir creates a folder.
  • cd changes directory.
  • touch creates a file.

To make it executable:

chmod +x myscript.sh

To run it:

./myscript.sh

Basic Batch Script (Windows)

On Windows, basic scripting is often done using batch files.

Create a file called:

myscript.bat

Example:

@echo off

echo Hello, world!
echo This is my first script.

mkdir TestFolder
cd TestFolder
type nul > example.txt

echo Script finished.
pause

Explanation:

  • @echo off hides command repetition.
  • echo prints text.
  • mkdir creates a folder.
  • cd changes directory.
  • type nul > file.txt creates a file.
  • pause waits for user input.

To run it:

Double-click the file

or run from Command Prompt:

myscript.bat

Variables in Scripts

Scripts can store information using variables.

Bash Example

#!/bin/bash

name="John"
echo "Hello, $name"

Windows Batch Example

@echo off

set name=John
echo Hello, %name%
pause

Variables allow your script to become dynamic.

Simple User Input

Bash

#!/bin/bash

echo "Enter your name:"
read name
echo "Hello, $name"

Windows Batch

@echo off

set /p name=Enter your name:
echo Hello, %name%
pause

Now the script interacts with the user.

Basic Conditional Logic

Scripts can make decisions.

Bash

#!/bin/bash

number=10

if [ $number -gt 5 ]; then
    echo "Number is greater than 5"
fi

Windows Batch

@echo off

set number=10

if %number% GTR 5 (
    echo Number is greater than 5
)

pause

This allows scripts to behave differently depending on conditions.

Basic Loop Example

Loops repeat commands.

Bash

#!/bin/bash

for i in 1 2 3
do
    echo "Number $i"
done

Windows Batch

@echo off

for %%i in (1 2 3) do (
    echo Number %%i
)

pause

How Scripts Work Internally

When you run a script:

  1. The shell reads the file.
  2. It interprets each line.
  3. It executes commands one by one.
  4. It stops if an error occurs (depending on settings).

A script is not compiled like a traditional program.

It is interpreted line by line.

# Bash Script Example
#!/bin/bash
echo "Hello, world!"
echo "This is my first script."
mkdir TestFolder
cd TestFolder
touch example.txt
echo "Script finished."

# Make executable
chmod +x myscript.sh
./myscript.sh

# Bash Variable Example
name="John"
echo "Hello, $name"

# Bash Input Example
echo "Enter your name:"
read name
echo "Hello, $name"

# Bash Conditional
number=10
if [ $number -gt 5 ]; then
    echo "Number is greater than 5"
fi

# Bash Loop
for i in 1 2 3
do
    echo "Number $i"
done

@echo off
echo Hello, world!
echo This is my first script.
mkdir TestFolder
cd TestFolder
type nul > example.txt
echo Script finished.
pause

set name=John
echo Hello, %name%
pause

set /p name=Enter your name:
echo Hello, %name%
pause

set number=10
if %number% GTR 5 (
    echo Number is greater than 5
)
pause

for %%i in (1 2 3) do (
    echo Number %%i
)
pause
QUICK KNOWLEDGE CHECK

Test Your Understanding

Answer 5 questions generated from this lesson. Your result is calculated instantly and is not saved.

0 / 5 answered
All Courses
Advance AI Bootstrap C C++ Computer Vision Content Writing CSS Cyber Security Data Analysis Deep Learning Email Marketing Excel Figma HTML Java Script Machine Learning MySQLi Node JS PHP Power Bi Python Python for AI Python for Analysis React React Native SEO SMM SQL
Course contents
Cyber Security
01 Introduction 02 Types of Cyber Threats 03 Cyber Security Domains 04 CIA Triad (Confidentiality Integrity Availability) 05 Career paths in Cyber Security 06 Certifications 07 Ethics and Responsible Disclosure 08 Laws and Regulation (e.g. GDPR, NDPR) 09 What is an OS? 10 Types: Window, Linus, macOS 11 Command-line vs GUI 12 OS Internals Overview (filesystems, processes, permissions) 13 Windows command prompt basics 14 Linux Bash Basics 15 File System Navigation 16 Basic Scripting 17 IP Addressing 18 DNS, DHCP 19 Mac Address 20 OSI VS TCP/IP Models 21 Ports and Protocols (TCP, UDP) 22 Common Protocols (HTTPS, FTP, SSH, etc.) 23 Packet structure 24 Firewalls, IDS/IPS, VPNs 25 Common attacks: MITM, Sniffing 26 Secure Network Practices 27 How the Web works 28 HTTP vs HTTPS 29 URLs, Headers, Cookies 30 Client-Server Architecture 31 Introduction To Web Security 32 OWASP Top 10 Overview 33 Common Threats (XSS, SQLi, CSRF) 34 Inpute validation and authentication flow 35 Basic Exploitation demo (e.g. XSS) 36 Burp Suite Introduction 37 Using a Browser For Testing 38 Password security 39 MFA-Antivirus 40 Cyber Hygeine Practice 41 Intro To Tools: Nmap, Wireshark, Netstat