2025-03-14 21:59:59 -06:00
# [
> Check file types and compare values.
> Returns a status of 0 if the condition evaluates to true, 1 if it evaluates to false.
2026-02-18 06:55:01 -07:00
> See also: `test`.
2025-03-14 21:59:59 -06:00
> More information: <https://gnu.org/software/bash/manual/bash.html#index-test>.
2026-02-18 06:55:01 -07:00
- Test if a given variable is equal to the specified string:
2025-03-14 21:59:59 -06:00
2026-02-18 06:55:01 -07:00
`[ "${{variable}}" = "{{string}}" ]`
- Test if a given variable is not equal to the specified string:
`[ "${{variable}}" != "{{string}}" ]`
2025-03-14 21:59:59 -06: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:
`[ "${{variable}}" -{{eq|ne|gt|lt|ge|le}} {{integer}} ]`
- Test if the specified variable has a [n]on-empty value:
`[ -n "${{variable}}" ]`
2025-04-25 19:33:51 -06:00
- Test if the specified variable has an empty value ([z]ero length):
2025-03-14 21:59:59 -06:00
`[ -z "${{variable}}" ]`
- Test if the specified [f]ile exists:
`[ -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}} ]`