* [: 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.
26 lines
729 B
Markdown
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 "偽"}}`
|