「Transwiki:Bash Shell Scripting」の版間の差分

削除された内容 追加された内容
Fu7mu4 (トーク | 投稿記録)
Fu7mu4 (トーク | 投稿記録)
564 行
このテストコマンド<source lang="bash" enclose="none">[[ -e source.txt ]] && ! [[ -e destination.txt ]]</source> は <tt>&&</tt> と <tt>!</tt> の演算子を使っており、この条件は <tt>''condition''</tt>が真のときに、<tt>[[<nowiki/> ''condition'' ]]</tt> が "真(successful)"を返すことを利用しています。つまり<source lang="bash" enclose="none">[[ -e source.txt ]] && ! [[ -e destination.txt ]]</source>がは、<tt>source.txt</tt>が存在する場合に<source lang="bash" enclose="none">! [[ -e destination.txt ]]</source>を実行します。さらに言えば、<tt>!</tt>は<source lang="bash" enclose="none">[[ -e destination.txt ]]</source>の終了値を逆転させるので、<source lang="bash" enclose="none">! [[ -e destination.txt ]]</source>が成功するのは、<tt>destination.txt</tt>が存在''しない''場合です。そのため、<source lang="bash" enclose="none">[[ -e source.txt ]] && ! [[ -e destination.txt ]]</source>が''真''を返すのは、<tt>source.txt</tt>が存在し、<tt>destination.txt</tt>が存在しない場合だけです。
 
<source lang="bash" enclose="none">[[ … ]]</source>構文は実際に、これらの演算子をビルトインで内部的にサポートしているので上の例は次のように書けます。
 
The construction <source lang="bash" enclose="none">[[ … ]]</source> actually has built-in internal support for these operators, such that we can also write the above this way:
 
<source lang="bash">#!/bin/bash
574 ⟶ 573行目:
fi</source>
 
but the general-purpose notations are often more clear; and of course, they can be used with any test-command, not just the しかし、一般的な表記はよりクリアです。それはあらゆるテストコマンドを使用できるため、<source lang="bash" enclose="none">[[ … ]]</source> construction.構文だけではないからです。
 
===可読性の注意===