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

削除された内容 追加された内容
Fu7mu4 (トーク | 投稿記録)
Fu7mu4 (トーク | 投稿記録)
553 行
===条件の組み合わせ===
 
複数の条件を "and" または "or"で組合せ、また 逆転させる"not"を使って、今までに見た Bashの表記をより一般的な表記にしましょう。次の例を考えましょう。
To combine multiple conditions with "and" or "or", or to invert a condition with "not", we can use the general Bash notations we've already seen. Consider this example:
 
<source lang="bash">#!/bin/bash
562 行
fi</source>
 
The test-command このテストコマンド<source lang="bash" enclose="none">[[ -e source.txt ]] && ! [[ -e destination.txt ]]</source> uses the <tt>&&</tt> and <tt>!</tt> operators that we saw above that work based on exit status.の演算子を使っており、この条件は <tt>''condition''</tt>が真のときに、<tt>[[<nowiki/> ''condition'' ]]</tt> is "真(successful)" if <tt>''condition''</tt> is true, which means that を返すことを利用しています。つまり<source lang="bash" enclose="none">[[ -e source.txt ]] && ! [[ -e destination.txt ]]</source> will only run がは、<tt>source.txt</tt>が存在する場合に<source lang="bash" enclose="none">! [[ -e destination.txt ]]</source> if <tt>source.txt</tt> exists. Furthermore, を実行します。さらに言えば、<tt>!</tt> inverts the exit status of <source lang="bash" enclose="none">[[ -e destination.txt ]]</source>, so that の終了値を逆転させるので、<source lang="bash" enclose="none">! [[ -e destination.txt ]]</source> is "successful" if and only if が成功するのは、<tt>destination.txt</tt> が存在''doesnしない't'' exist. The end result is that 場合です。そのため、<source lang="bash" enclose="none">[[ -e source.txt ]] && ! [[ -e destination.txt ]]</source> is "successful" — "true" — if and only if が''真''を返すのは、<tt>source.txt</tt> ''does'' exist and が存在し、<tt>destination.txt</tt> does ''not'' exist.が存在しない場合だけです。
 
 
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: