1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-23 00:42:08 +02:00
tldr/pages/common/test.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

656 B

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/test.

  • Test if a given variable is equal to a given string:

test "{{$MY_VAR}}" = "{{/bin/zsh}}"

  • Test if a given variable is empty:

test -z "{{$GIT_BRANCH}}"

  • Test if a file exists:

test -f "{{path/to/file_or_directory}}"

  • Test if a directory 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"}}