Files
tldr/pages/common/[.md
Gabe Livengood 9d865abee1 test: Use POSIX-compliant example for equals comparison (#11728)
* [: use posix-compliant example for equals comparison

the previous example worked fine for bash, but some
other shells (zsh, in my case) will not work when
using "==" for comparison. the posix spec only requires
"=", so I think it makes a little more sense to use
that in the example.

* test: use posix-compliant example for equals comparison

the previous example worked fine for bash, but some
other shells (zsh, in my case) will not work when
using "==" for comparison. the posix spec only requires
"=", so I think it makes a little more sense to use
that in the example.
2023-12-14 20:31:13 +05:30

34 lines
952 B
Markdown

# [
> Check file types and compare values.
> Returns a status of 0 if the condition evaluates to true, 1 if it evaluates to false.
> More information: <https://www.gnu.org/software/bash/manual/bash.html#index-test>.
- Test if a given variable is equal/not equal to the specified string:
`[ "${{variable}}" {{=|!=}} "{{string}}" ]`
- 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}}" ]`
- Test if the specified variable has an empty value:
`[ -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}} ]`