2021-03-10 19:24:11 +00:00
# [
2021-11-07 00:57:43 +00:00
> Check file types and compare values.
2023-05-16 20:22:48 +01:00
> Returns a status of 0 if the condition evaluates to true, 1 if it evaluates to false.
2024-09-10 19:36:38 +01:00
> More information: <https://gnu.org/software/bash/manual/bash.html#index-test>.
2021-03-10 19:24:11 +00:00
2021-12-21 21:28:01 +00:00
- Test if a given variable is equal/not equal to the specified string:
2021-03-10 19:24:11 +00:00
2023-12-14 15:01:13 +00:00
`[ "${{variable}}" {{=|!=}} "{{string}}" ]`
2021-03-10 19:24:11 +00:00
2021-12-21 21:28:01 +00:00
- Test if a given variable is [eq]ual/[n]ot [e]qual/[g]reater [t]han/[l]ess [t]han/[g]reater than or [e]qual/[l]ess than or [e]qual to the specified number:
2021-03-10 19:24:11 +00:00
2021-12-21 21:28:01 +00:00
`[ "${{variable}}" -{{eq|ne|gt|lt|ge|le}} {{integer}} ]`
2021-03-10 19:24:11 +00:00
2021-12-21 21:28:01 +00:00
- Test if the specified variable has a [n]on-empty value:
2021-03-10 19:24:11 +00:00
2021-12-21 21:28:01 +00:00
`[ -n "${{variable}}" ]`
2021-03-10 19:24:11 +00:00
2021-12-21 21:28:01 +00:00
- Test if the specified variable has an empty value:
2021-03-10 19:24:11 +00:00
2021-12-21 21:28:01 +00:00
`[ -z "${{variable}}" ]`
2021-03-10 19:24:11 +00:00
2021-12-21 21:28:01 +00:00
- Test if the specified [f]ile exists:
2021-03-10 19:24:11 +00:00
2021-12-21 21:28:01 +00:00
`[ -f {{path/to/file}} ]`
- Test if the specified [d]irectory exists:
`[ -d {{path/to/directory}} ]`
- Test if the specified file or directory [e]xists:
`[ -e {{path/to/file_or_directory}} ]`