1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-29 23:24:55 +02:00
tldr/pages.pl/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

635 B

test

Sprawdza typy plików i porównuje wartości. Zwraca 0 gdy porównanie zwróciło wartość poprawną, 1 gdy fałszywą. Więcej informacji: https://www.gnu.org/software/coreutils/test.

  • Sprawdź czy podana zmienna jest równa łańcuchowi znaków:

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

  • Sprawdź czy zmienna jest pusta:

test -z "{{$GIT_BRANCH}}"

  • Sprawdź czy plik istnieje:

test -f "{{ścieżka/do/pliku}}"

  • Sprawdź czy katalog nie istnieje:

test ! -d "{{ścieżka/do/katalogu}}"

  • Zapis jeśli porawne-jeśli fałszywe:

test {{warunek}} && {{echo "gdy poprawne"}} || {{echo "gdy fałszywe"}}