This is Part 2 of Linux Shell Tutorials Series, in this tutorial
we will see STRING operators that are commonly used in shell scripts
.
For executing these scripts provide Strings as script arguments.
#!/bin/bash
echo "$1"
if test -z $1; then
echo "provided string is empty"
fi
#!/bin/bash
echo "$1"
if test -n $1; then
echo "provided string is not empty"
fi
#!/bin/bash
echo "$1 $2"
if test $1 = $2; then
echo "provided strings are equal"
fi
#!/bin/bash
echo "$1 $2"
if test $1 != $2; then
echo "provided strings are not equal"
fi
#!/bin/bash
echo "$1 $2"
if test $1 \< $2;then
echo "$1 comes before $2 alphabetically"
fi
#!/bin/bash
echo "$1 $2"
if test $1 \> $2;then
echo "$1 comes after $2 alphabetically"
fi
Similar Articles