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

削除された内容 追加された内容
Fu7mu4 (トーク | 投稿記録)
M タイトルのみ→‎Arithmetic for-loops
Fu7mu4 (トーク | 投稿記録)
1,083 行
===整数リテラル===
 
整数定数は「整数リテラル」で表現します。今までみてきたように、例えば<tt>34</tt>は数字の34を表わす整数リテラルです。私たちがみてきた例は全て10進数(基数10)の整数リテラルでした。10進数がデフォルトです。しかしbashでは基数に2&ndash;64 の整数リテラルを表現できます。この場合<tt><var>基数</var>#<var>値</var></tt>という表記方法を使用します。基数自体は10進数で表現してください。例を挙げます。
An integer constant is expressed as an ''integer literal''. We have already seen many of these; <tt>34</tt>, for example, is an integer literal denoting the number 34. All of our examples have been ''decimal'' (base ten) integer literals, which is the default; but in fact, literals may be expressed in any base in the range 2&ndash;64, using the notation <tt><var>base</var>#<var>value</var></tt> (with the base itself being expressed in base-ten). For example, this:
 
'''echo''' $'''((''' 12 '''))''' # use the default of base ten 基数が10の10進数、デフォルト(decimal)
'''echo''' $'''((''' 10#12 '''))''' # explicitly specify base ten明示的に基数を表示した10進数 (decimal)
'''echo''' $'''((''' 2#1100 '''))''' # base two基数2の2進数 (binary)
'''echo''' $'''((''' 8#14 '''))''' # base eight基数8の8進数 (octal)
'''echo''' $'''((''' 16#C '''))''' # base sixteen基数16の16進数 (hexadecimal)
'''echo''' $'''((''' 8 + 2#100 '''))''' # eight基数10の10進数であらわした in base ten8 (decimal), plus基数2の2進数であらわした four in base two (binary)4の和
 
これらはそれぞれ <tt>12</tt> を表示します。(この表記方法は整数リテラルをどのように解釈するかだけに影響します。算術式表現の結果は10進数のままです。)
will print <tt>12</tt> six times. (Note that this notation only affects how an integer literal is interpreted. The result of the arithmetic expansion is still expressed in base ten, regardless.)
 
For bases基数が 11 throughから 36, the English lettersの範囲では英語文字の A throughから Z are used for digit-valuesを使用します。これらの文字はそれぞれ 10 throughから 35. This is not case-sensitive. For bases に相当しますが、大文字小文字は同一視します。基数が37 throughから 64,では違います。a however,から it is specifically the lowercase English letters that are used for digit-valuesz 10 throughから 35, with the uppercase letters being used for digit-values 36 through に、AからZを37じゃら61, the at-signに相当させます。アットマークは <tt>@</tt> being used for digit-value 62, and the underscoreアンダースコア、アンダーライン <tt>_</tt> being used for digit-value 63. For example,に相当します。例えば <tt>64#@A3</tt> denotes 256259 (<span style="white-space:nowrap">62 × 64<sup>2</sup> + 36 × 64 + 3</span>).
 
There are also two special notations: prefixing a literal with ここで特別な表記方法が二つあります。先頭が<tt>0</tt> indicates base-eight (octal), and prefixing it with のリテラルは基数8の8進数を表します。先頭が<tt>0x</tt> orまたは <tt>0X</tt> indicates base-sixteen (hexadecimal). For example,のリテラルは基数16の16進数を表します。例えば <tt>030</tt> is equivalent to <tt>8#30</tt>, and <tt>0x6F</tt> is equivalent to <tt>16#6F</tt>.です。
 
===整数変数===