Strings

Python Strings A string is a sequence of characters. The Python treated any sequence of character enclosed in quotes as string.

Use any of the above quotes, the result will remain in single quote in Python. ie. ‘Welcome’ String Concatenation In Python strings have operation symbols too. Using a plus (+) symbol concatenate two strings. let’s type below example on Python shell.

The result will be same ‘Hello World’ Next, try with some digits enclosed with and without quotes.

Python checks for the types of values, based…

Read More

Concatenate string variables

Brief: This example will help you to concatenate two or more strings variable in a bash script. This tutorial helps you with multiple shell script examples of concatenating strings in a shell script. The first example is a general way to concatenate variables of string. You can simply write all the variable one after another:

Output: Welcome TecAdmin! Another Example You can also use += operator to concatenate two strings and store results in the first string.

Output: Welcome TecAdmin! One More Example Use another example with one…

Read More

Check if two strings are equal?

Bash – Check If Two Strings are Equal Brief: This example will help you to understand to check if two strings are equal in a bash script. This shell script accepts two string in variables and checks if they are identical. Details Use == operator with bash if statement to check if two strings are equal. You can also use != to check if two string are not equal. You must use single space before and after the == and != operators. Example In this script two variables are initialized…

Read More

Bash – String Comparisons

Bash String Comparisons Use double equals ( == ) operator to compare strings inside square brackets []. Using this option you simply test if two given strings are equals or not inside bash shell scripts. Example Syntax: if [ “$str1” == “$str2” ] # True if equal if [ “$str1” != “$str2” ] # True if not equal Example: For example to compare two string are equal or not. if [ “hello” == “hello” ] ## True if [ “hello” == “hello1” ] ## False if [ “hello” != “hello”…

Read More