The [
command (also known as the test
command) is a built-in shell command that is used to evaluate expressions and perform conditional tests. It is typically used in shell scripts to check the value of a variable or the existence of a file or directory.
The [
command is usually followed by an expression that is surrounded by square brackets ([
and ]
) and one or more options or arguments. The expression is evaluated as either true or false, depending on the specified conditions.
Here are some examples of how you can use the [
command:
-e
option followed by the file's name:[ -e file_name ]
This will return a true value if the specified file exists and a false value if it does not.
-f
option followed by the file's name:[ -f file_name ]
This will return a true value if the specified file is a regular file and a false value if it is not.
-n
option followed by the variable's name:[ -n "$variable" ]
This will return a true value if the specified variable has a non-empty value and a false value if it is empty.
=
operator:[ "$variable_1" = "$variable_2" ]
This will return a true value if the two variables have the same value and a false value if they do not.
For more information about the [
command and its available options, you can consult the test
man page or use the [ --help
command.