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

削除された内容 追加された内容
Fu7mu4 (トーク | 投稿記録)
Fu7mu4 (トーク | 投稿記録)
616 行
done</source>
 
In fact, that specific case is so common that 実際、よく現れる特定の場合のためにBash provides the equivalent shorthand は同等の省略形を用意しています。<source lang="bash" enclose="none">for arg ; do</source>, with ここでは<source lang="bash" enclose="none">in "$@"</source> being implied. が省略されている(But it's probably better to use the explicit form anyway.しかし明示した形式のほうがより分かりやすいです。)
 
その他の種類のループには<tt>while</tt>ループがあります。これは<tt>if</tt>ステートメントに似ていますが、テストコマンドが成功する限りそのLOOPを繰り返すところが違います。例えば、<tt>wait.txt</tt>が削除されるまで待つ必要があったとします。一つの方法として数秒間 ''休み(sleep)'' してその後に''起動''し、そのファイルがあるか確認します。この方法を繰り返しループさせることができます。
Another kind of loop is the <tt>while</tt> loop. It is similar to an <tt>if</tt> statement, except that it loops repeatedly as long as its test-command continues to be successful. For example, suppose that we need to wait until the file <tt>wait.txt</tt> is deleted. One approach is to "sleep" for a few seconds, then "wake up" and see if it still exists. We can loop repeatedly in this fashion:
 
<source lang="bash">while [[ -e wait.txt ]] ; do
624 行
done</source>
 
これとは逆に、<tt>until</tt>ループも使用できます。これは、与えられたコマンドが''成功するまで''ループを繰り返します。上の逆になります。
Conversely, we can use an <tt>until</tt> loop to loop ''until'' a given command is successful; for example, the reverse of the above might be:
 
<source lang="bash">until [[ -e proceed.txt ]] ; do
630 行
done</source>
 
もちろん、これは<tt>while</tt> と <tt>!</tt>を組み合わせると同じになります。しかしいくつかの場合では、より読みやすくなります。
Of course, this is the same as combining <tt>while</tt> with <tt>!</tt>, but in some cases it may be more readable.
* Just like <tt>if</tt>, と同様に<tt>while</tt> judges <tt>真(true)</tt> orまたは <tt>偽(false)</tt> in the same way. Try it out yourself.を判断します。いくつか試してください。
 
==シェル関数==