Shell introduction
Shell introduction
introduction
String processing
Bash is a shell language used in Linux systems that
allows users to interact with system through
command-line interface.
Bash offers several string manipulation capabilities
that can help users manipulate and process text
strings
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.
Basic String Operations
Bash provides basic operations for manipulating strings.
To create a string variable in Bash, you simply assign a
value to a variable name
Mystring=“Hello, world!”
To display contents of string variable, you can use echo
command –
echo $mystring
The output will be
hello,world!
echo ${#mystring}
string1="Hello,“
string2=" world!"
echo ${string1}${string2}
The output will be −
Hello,world!
Equal Operator
str1="WelcometoJavatpoint."
str2="javatpoint"
if [ $str1 = $str2 ];
then
echo "Both the strings are equal."
else
echo "Strings are not equal."
fi
Like wise following operators are used
Not Equal Operator
Less than Operator
Greater than Operator
To check if the string length is greater than Zero: