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

719 B

test

条件を評価します。 条件が真と評価された場合は 0 を、偽と評価された場合は 1 を返します。 詳しくはこちら: https://www.gnu.org/software/coreutils/test

  • 与えられた変数が与えられた文字列と等しいかどうかをテスト:

test "{{$変数名}}" = "{{/bin/zsh}}"

  • 与えられた変数が空であるかどうかをテスト:

test -z "{{$変数名}}"

  • ファイルが存在するかどうかをテスト:

test -f "{{ファイルへのパス}}"

  • ディレクトリが存在しないかどうかをテスト:

test ! -d "{{ディレクトリへのパス}}"

  • if-else 文:

test {{条件}} && {{echo "真"}} || {{echo "偽"}}