String Operators | Shell Script Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share 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 Shell Script to Split a String B bilal-hungund Follow Improve Article Tags : Technical Scripter Linux-Unix Web Technologies Technical Scripter 2018 Shell Script +1 More Similar Reads Shell Scripting - Here Strings Here String is a kind of string that is used for input redirection from text or a variable. In here string Input will be mentioned in the same line within the quotes. the string inside the quotes is known as the Here string and Its command contains "<<<" (3 less than the symbol). Here strin 2 min read Shell Script to Join a String There are different ways to concatenate strings in the shell. Some of them are listed below. String concatenation is used in shell scripting to make it much easier for the user to understand and use the program. Appending strings also allow the programmer to learn the working of concatenation on the 3 min read String Manipulation in Shell Scripting String Manipulation is defined as performing several operations on a string resulting change in its contents. In Shell Scripting, this can be done in two ways: pure bash string manipulation, and string manipulation via external commands. Basics of pure bash string manipulation: 1. Assigning content 4 min read Shell Script to Split a String Shell Scripting or Shell Programming is just like any other programming language. A shell is a special program that provides an interface between the user and the operating system. In Linux/Unix the default shell used is bash and in windows, it is cmd(command prompt). We use the terminal to run a sh 3 min read Shell Script to Concatenate Two Strings String concatenation is the process of appending a string to the end of another string. This can be done with shell scripting using two methods: using the += operator, or simply writing strings one after the other. The examples below show some shell scripts that can be used to concatenate strings. E 3 min read Bash Scripting - Split String In this article, we will discuss how to split strings in a bash script. Dividing a single string into multiple strings is called string splitting. Many programming languages have a built-in function to perform string splitting but there is no built-in function in bash to do so. There are various met 4 min read Like