test command is used to check the validity of an expression. It checks whether a command or an expression is true or false. Also, it can be used to check the type and permissions of a file.
for example :
if [ type -e $file_name ]
then
echo "The $file_name exists"
else
echo "The $file_name does not exists"
fi
here type -e will check whether the particular file exists or not
In Bash, `test` directive is a utility for evaluating expressions within `if` conditions. `test` command evaluate expression and return 0 as the status code if the expression is true else it returns non zero value. we can either use `test` command or `[ ]` to use `test` directive.