String Comparison Operators
String comparison operators are used to compare strings within square brackets.
Operators:
=
: Equal to!=
: Not equal to-z
: String is null (zero length)-n
: String is not null (non-zero length)
Example:
#!/bin/bash
if [ "$1" = "hello" ]; thenSquare brackets ([ and ]) are essential components in Bash scripting.
They are used for a variety of purposes, including conditional expressions, string and numerical comparisons, and file tests.
This article provides a comprehensive overview of square brackets in Bash, exploring their uses and functionalities.
echo "Hello, World!"
elif [ -z "$1" ]; then
echo "No input provided."
else
echo "Input is not 'hello'."
fi
Output:
$ ./script.sh hello
Hello, World!
$ ./script.sh
No input provided.
$ ./script.sh hi
Input is not 'hello'.
Using Square Brackets in Bash
Square brackets ([
and ]
) are essential components in Bash scripting. They are used for a variety of purposes, including conditional expressions, string and numerical comparisons, and file tests. This article provides a comprehensive overview of square brackets in Bash, exploring their uses and functionalities.