String Operators | Shell Script Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Pre-Requisite: Conditional Statement in Shell Script There are many operators in Shell Script some of them are discussed based on string. Equal operator (=): This operator is used to check whether two strings are equal. Syntax:Operands1 = Operand2Example: php #!/bin/sh str1="GeeksforGeeks"; str2="geeks"; if [ $str1 = $str2 ] then echo "Both string are same"; else echo "Both string are not same"; fi Output:Both string are not sameNot Equal operator (!=): This operator is used when both operands are not equal. Syntax:Operands1 != Operands2Example: php #!/bin/sh str1="GeeksforGeeks"; str2="geeks"; if [ $str1 != $str2 ] then echo "Both string are not same"; else echo "Both string are same"; fi Output:Both string are not sameLess than (\<): It is a conditional operator and used to check operand1 is less than operand2. Syntax: Operand1 \< Operand2 Example: php #!/bin/sh str1="GeeksforGeeks"; str2="Geeks"; if [ $str1 \< $str2 ] then echo "$str1 is less than $str2"; else echo "$str1 is not less than $str2"; fi Output:GeeksforGeeks is not less than GeeksGreater than (\>): This operator is used to check the operand1 is greater than operand2. Syntax: Operand1 \> Operand2 Example: php #!/bin/sh str1="GeeksforGeeks"; str2="Geeks"; if [ $str1 \> $str2 ] then echo "$str1 is greater than $str2"; else echo "$str1 is less than $str2"; fi Output:GeeksforGeeks is greater than GeeksCheck string length greater than 0: This operator is used to check the string is not empty. Syntax:[ -n Operand ]Example: php #!/bin/sh str="GeeksforGeeks"; if [ -n $str ] then echo "String is not empty"; else echo "String is empty"; fi Output:String is not emptyCheck string length equal to 0: This operator is used to check the string is empty. Syntax:[ -z Operand ]Example: php #!/bin/sh str=""; if [ -z $str ] then echo "String is empty"; else echo "String is not empty"; fi Output:String is empty Comment More infoAdvertise with us Next Article Must Coding Questions - Company-wise B bilal-hungund Follow Improve Article Tags : Technical Scripter Linux-Unix Web Technologies Technical Scripter 2018 Shell Script +1 More Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like