Javatpoint Logo
Javatpoint Logo

Bash String

In this topic, we have demonstrated about bash string and its operators.

Like other programming languages, Bash String is a data type such as as an integer or floating-point unit. It is used to represent text rather than numbers. It is a combination of a set of characters that may also contain numbers.

For example, the word "javatpoint" and the phrase "Welcome to javatpoint" are the strings. Even "01234" could be considered as a string, if specified correctly. Programmers are required to enclose strings in quotation marks for the data to be considered as a string and not a number, variable name or array, etc.

Bash consists of multiple ways to perform string operations and manipulate them.

Following are some operators in Shell Script used to perform string operations:

Equal Operator

An equal operator (=) is used to check whether two strings are equal.

Syntax

Example

Output

Strings are not equal.

Not Equal Operator

Not equal operator (!=) is used to define that strings are not equal.

Syntax

Example

Output

Strings are not equal.

Less than Operator

The 'less than operator (\<)' is a conditional operator which is used to check if string1 is less than string2.

Syntax

Example

Output

WelcometoJavatpoint is not less then Javatpoint

Greater than Operator

The 'greater than operator (\>)` is used to check if string1 is greater than string2.

Syntax

Example

Output

WelcometoJavatpoint is greater then Javatpoint

To check if the string length is greater than Zero:

This operator is used to check if the string is zero or greater than zero.

Syntax

Example

Output

String is not empty

To check if the string length is equal to Zero

This operator is used to check if the string is empty or equal to zero.

Syntax

Example

Output

String is empty

Conclusion

In this topic, we have learned about the syntax of different operators in bash scripting with example scripts.


Next TopicBash Find String




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA