EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Unix Tutorial Unix Operators
Secondary Sidebar
Unix Tutorial
  • Basic
    • What is Unix
    • Uses of Unix
    • Career In Unix
    • Install UNIX
    • Unix Architecture
    • Unix Commands
    • VI Command in Unix
    • AWK Command in Unix
    • Paste Command in Unix
    • SED Command in Unix
    • Sort Command in Unix
    • WHO Command in Unix
    • Unix Operators
    • UNIX Administrator
  • Advanced
    • Array in Unix
    • Functions in Unix
    • Unix File Permissions
    • Unix File System
    • Unix Shell Commands
    • Crontab in Unix
    • egrep command in Unix
    • For Loop in Unix
    • VI Editor in Unix
    • What is Unix Shell
    • Gnome Development
    • UNIX interview questions
    • Cheat sheet for UNIX
    • Unix Sort by Column
    • Find Command in Unix
    • Gnome Version

Related Courses

Linux Training Course

Kali Linux Training

Red Hat Training Course

Unix Operators

By Priya PedamkarPriya Pedamkar

Unix Operators-1.1

Introduction to Unix Operators

Entities that enable operations between variables may be divided into different types, with a certain order of importance that occurs between them, and certain subcategories may also be present in each of these types. With a specific order of execution that exists for subcategories present in each form and each entity in a subcategory having its own special significance when dealing with the necessary number of variables. Operating with a logic that is unique to itself, and conforming to principles in mathematics, logic, or algorithms, in the sense of Unix programming, is referred to as Unix operators.

The Unix is made up of 3 parts: Kernel, shell, and programs.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,198 ratings)
  •  A Kernel is the core of Unix which manages time and memory for the tasks
  • Shell is the CLI ( Command Line interface ) between the kernel and the user. When a user logs in to the system he enters the shell where it accepts commands and calls the respective program to process the same.
  • Programs and Files – The various commands of Unix are documented in the manual which can be accessed by typing man <command>. There are also processes that run in the shell identified by their unique PID (process identifier). The files and directories stored inside Unix have a hierarchical structure/path starting with / meaning root location.

Types of Operators in Unix

There are 5 types of basic operators in Unix which are:
1. Arithmetic
2. Relational
3. Boolean
4. File Test Operators
5. Bitwise
Unix Operators-1.2

1) Arithmetic Operators

These are used for performing arithmetic mathematical operations. Following are some of the arithmetic operators:

  • Addition (+): Used to perform addition between 2 operands
    Ex: c=`expr $a + $b`
  • Subtraction (-): Used to perform a subtraction between 2 operands
    Ex: c=`expr $a – $b`
  • Multiplication (*): Used to multiply the value of 2 operands
    Ex: c=`expr $a \* $b`
  • Division (/): Used to divide the first operand by the second one
    Ex: c=`expr $a / $b`
  • Modulus (%): Used to provide remainder obtained by dividing the first operand by the second one
    Ex: f=`expr $a % $b`
  • • Assignment (=): Used to assign the value given in the second operand to the first one
    Ex: c=$b
  • Increment (++): Used to increment the value of the operand by 1.
    Ex: ((a++)) – Post increment, ((++a)) – Pre increment, ((a–)) – Post decrement, ((–a)) – Pre decrement

2) Relational Operators

These are used to compare and find out the relation between 2 operands. Following are some of the relational operators:

  • Equality (== or -eq): This returns true if both the operands are equal and false if not equal.
    Ex: $a == $b
  • Non-Equality (!= or -ne): This is the opposite of equality operator where it returns true if both the operands are not equal and vice versa.
    Ex: $a != $b
  • Greater than (> or -gt): This returns true if the first operand is greater than the second one and vice versa.
    Ex: $a > $b
  • Lesser than (< or -lt): This returns true if the first operand is lesser than the second one and vice versa.
    Ex: $a < $b
  • Greater than or Equal to (>= or -ge): This returns true if the first operand is greater than or equal to the second operand and false if not.
    Ex: $a >= $b
  • Lesser than or Equal to (<= or -le): This returns true if the first operand is lesser than or equal to the second operand and false if not.
    Ex: $a <= $b

3) Boolean/ Logical Operators

These are used to perform logical operators on the operands.

  • Logical AND (&& or -a): This returns a Boolean true value if both operands satisfy true condition else returns false.
    Ex: When a=20 and b=5 this [ $a -lt 10 -a $b -gt 1] becomes false since a is not less than 10
  • Logical OR (|| or -o): This returns a Boolean true value if any one of the operands satisfies the condition else returns false.
    Ex: When a=20 and b=5 this [ $a -lt 10 -o $b -gt 1s] becomes true since b greater than 1 is true
  • Not Equal to (!): This returns a Boolean true value if the operand value is false and vice versa.
    Ex: If a=true [! $a == true] is false

4) File Operators

These are used to test the properties associated with the various files of the Unix filesystem.

  • -b operator: This will be true when the file exists and is a special block file else will return false
  • -c operator: This will be true when the file exists and is a character special file else will return false.
  • -d operator: This will return true if the given filename is a directory else will return false.
  • -e operator: This will return true if the given file exists else will return false.
  • -g operator: This operator will return true if the given file’s SGID (Set Group ID) bit is set to true.
  • -k operator: This will return true if the given file’s sticky bit is set to true.
  • -r operator: This will return true if the given file is readable by the logged in user else will return false.
  • -s operator: This checks the size of the given file and returns true if it is greater than zero else will return false.
  • -u operator: This will return true if the given file has its SUID (Set User ID) bit set to true.
  • -w operator: This will return true if the given file has to write access by the user else will return false.
  • -x operator: This will check and return true if the given file can be executed by the user else will return false.

5) Bitwise Operators

These are used to perform bitwise operations on the operands.

  • Bitwise AND (&): Here the AND operation is performed on each bit of the operand.
    Ex: Consider a = 55 and b = 23 for all below examples
    a & b = 01
  • Bitwise OR (|): Here the OR operation is performed on each bit of the operand.
    Ex: a | b = 77
  • Bitwise XOR (^): Here the XOR operation is performed on each of operand.
    Ex: a ^ b = 76
  • Complement (~): This performs the complement on each bit of the operand and returns the value.
    Ex: ~a = AA

Arithmetic operators can be used independently whereas the other types of operators need to be clubbed with conditional statements like if, switch statements to use its functionality.
This concludes the major types of operators in Unix along with their examples.

Recommended Articles

This is a guide to Unix Operators. Here we discuss the basic concept and types of operators in Unix which includes arithmetic, relational, boolean and bitwise in detail. You may also look at the following articles to learn more –

  1. VB.NET Operators
  2. Career In Unix
  3. Cheat sheet for UNIX
  4. Functions in Unix
Popular Course in this category
Linux Training Program (16 Courses, 3+ Projects)
  16 Online Courses |  3 Hands-on Projects |  160+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Kali Linux Training (3 Courses, 3+ Projects)4.9
Red Hat Linux Training Program (4 Courses, 1+ Projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more