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

削除された内容 追加された内容
Fu7mu4 (トーク | 投稿記録)
Fu7mu4 (トーク | 投稿記録)
1,131 行
===非整数の演算===
 
説明したように、Bashシェルの演算は整数演算のみをサポートしています。このような場合、整数演算以外の計算機能を持つ類似の外部プログラムが助けになります。特によく使用されるUnixユーティリティには<tt>bc</tt>があります。次のコマンドは<tt>3.4 + 2.2=5.6</tt>を計算します。
As mentioned above, Bash shell arithmetic only supports integer arithmetic. However, external programs can often be used to obtain similar functionality for non-integer values. In particular, the common Unix utility <tt>bc</tt> is often used for this. The following command:
 
<source lang="bash">echo "$(echo '3.4 + 2.2' | bc)"</source>
 
上の例は <tt>5.6</tt>と表示します。言うまでもありませんが、<tt>bc</tt> はBashシェル演算に統合されていないので、便利ではありません。例えば次を見てください。
prints <tt>5.6</tt>. Needless to say, since <tt>bc</tt> is not so tightly integrated with Bash as shell arithmetic is, it is not as convenient; for example, something like this:
 
<source lang="bash">
1,144 行
</source>
 
これを非整数演算で行うと次のようになります。
would, to support non-integers, become something like this:
 
<source lang="bash">