1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-07-05 10:55:24 +02:00
tldr/pages/common/test.md
Pranaov S 8bc9dce9b1
pages/common/*: correct urls, see also improvements, unbashify pages, examples addition (#16841)
Co-authored-by: Managor <42655600+Managor@users.noreply.github.com>
Co-authored-by: Sebastiaan Speck <12570668+sebastiaanspeck@users.noreply.github.com>
Co-authored-by: Lena <126529524+acuteenvy@users.noreply.github.com>
2025-06-14 19:02:15 +03:00

29 lines
846 B
Markdown

# test
> Check file types and compare values.
> Returns 0 if the condition evaluates to true, 1 if it evaluates to false.
> More information: <https://www.gnu.org/software/coreutils/manual/html_node/test-invocation.html>.
- Test if a given variable is equal to a given string:
`test "{{$MY_VAR}}" = "{{/bin/zsh}}"`
- Test if a given variable is empty ([z]ero length):
`test -z "{{$GIT_BRANCH}}"`
- Test if a [f]ile exists:
`test -f "{{path/to/file_or_directory}}"`
- Test if a [d]irectory does not exist:
`test ! -d "{{path/to/directory}}"`
- If A is true, then do B, or C in the case of an error (notice that C may run even if A fails):
`test {{condition}} && {{echo "true"}} || {{echo "false"}}`
- Use `test` in a conditional statement:
`if test -f "{{path/to/file}}"; then echo "File exists"; else echo "File does not exist"; fi`