Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 2.29 KB

1.md

File metadata and controls

58 lines (40 loc) · 2.29 KB

Chapter 3: The Operator Odyssey 🤖

1 - The What, Why and How's of operators in linux

Understanding Operators in Linux

What are Operators in Linux?

Operators in Linux are symbols or characters used to perform specific operations on data within shell scripts or commands. These operations include arithmetic calculations, logical comparisons, and bitwise manipulations. Operators play a crucial role in scripting and command-line operations, allowing users to perform various tasks efficiently.

Types of Operators in Linux

1. Arithmetic Operators

Arithmetic operators are used for performing mathematical operations such as addition, subtraction, multiplication, division, and modulus.

  • + (Addition)
  • - (Subtraction)
  • * (Multiplication)
  • / (Division)
  • % (Modulus)

2. Relational Operators

Relational operators are used to compare values and determine the relationship between them.

  • > or -gt (Greater than)
  • < or -lt (Less than)
  • >= or -ge (Greater than or equal to)
  • <= or -le (Less than or equal to)
  • == or -eq (Equal to)
  • != or -ne (Not equal to)

3. Logical Operators

Logical operators are used to perform logical operations such as AND, OR, and NOT.

  • && or -a (Logical AND)
  • || or -o (Logical OR)
  • ! (Logical NOT)

4. Bitwise Operators

Bitwise operators are used to perform operations on individual bits of binary numbers.

  • & (Bitwise AND)
  • | (Bitwise OR)
  • ^ (Bitwise XOR)
  • ~ (Bitwise NOT)
  • << (Left shift)
  • >> (Right shift)

Why Use Operators in Linux?

Operators in Linux provide a powerful and efficient way to manipulate data, make decisions, and control the flow of execution within shell scripts and commands. They enable users to perform complex calculations, comparisons, and logical operations, making scripting and command-line tasks more flexible and versatile.

How to Use Operators in Linux

To use operators in Linux, simply include them in your shell scripts or commands along with the operands on which the operations are to be performed. Operators are typically placed between operands, and their behavior depends on the type of operation being performed.

⬅️Previous-----------Next ➡️

Table of contents 🚀