Bash script: String comparison examples - JohnHau/mis GitHub Wiki

The need to compare strings in a Bash script is relatively common and can be used to check for certain conditions before proceeding on to the next part of a script.

A string can be any sequence of characters. To test if two strings are the same, both strings must contain the exact same characters and in the same order. It could be a word or a whole sentence. For example, string one is equal to string one but is not equal to string two. Get the idea?

In this tutorial, we’ll show you how to compare strings in a Bash script on a Linux system. We’ll show this in the context of a simple if/else Bash script so you can see how testing for this condition would work when developing scripts.

In this tutorial you will learn:

How to compare strings in Bash Example if/else Bash scripts that compare strings

Bash script: String comparison examples

image

image

image

image

image

image