Files
tldr/pages.ja/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

26 lines
729 B
Markdown

# [
> 条件を評価します。
> 条件が真と評価された場合は 0 を、偽と評価された場合は 1 を返します。
> 詳しくはこちら: <https://www.gnu.org/software/bash/manual/bash.html#index-test>
- 与えられた変数が与えられた文字列と等しいかどうかをテスト:
`[ "{{$変数名}}" = "{{/bin/zsh}}" ]`
- 与えられた変数が空であるかどうかをテスト:
`[ -z "{{$変数名}}" ]`
- ファイルが存在するかどうかをテスト:
`[ -f "{{ファイルへのパス}}" ]`
- ディレクトリが存在しないかどうかをテスト:
`[ ! -d "{{ディレクトリへのパス}}" ]`
- if-else 文:
`[ {{条件}} ] && {{echo "真"}} || {{echo "偽"}}`