OSDN Git Service

バージョンの修正.
[omake-japanese/omake_trans.git] / shell.rst
1 .. 11-shell
2
3 .. _label11:
4
5 11. シェルコマンド
6 ==================================
7 .. Shell commands (commands to be executed by the operating system) can be freely mixed with other code.
8
9 シェルコマンド(OSによって実行されるコマンド)は自由に他のコードとミックスすることができます。
10
11 .. NOTE: the syntax and shell usage is identical on all platforms, including Win32. To avoid portability problems on Win32, it is recommended that you avoid the use of the native shell interpreter cmd.
12
13 .. note::
14     構文とシェルの使い方はすべてのプラットフォーム(Win32を含む)において同一です。Win32上に移植した場合の問題を避けるために、ネイティブのインタープリター ``cmd`` を使わないことをおすすめします。 ::
15
16         LIB = $(dir lib)
17         println(The contents of the $(LIB) directory is:)
18         ls $(LIB)
19
20 .. _label11.1:
21
22 11.1 簡単なコマンド
23 ----------------------------------
24 .. The syntax of shell commands is similar to the syntax used by the Unix shell bash. In general, a command is a pipeline. A basic command is part of a pipeline. It is specified with the name of an executable and some arguments. Here are some examples.
25
26 シェルコマンドの構文はUnixシェル ``bash`` を使うときの構文と似ています。
27 通常、コマンドは *パイプライン* となっています。通常のコマンドはパイプラインの一部です。コマンドを実行するためには、実行可能なコマンド名といくつかの引数を指定する必要があります。以下はいくつかの例です。 ::
28
29     ls
30     ls -AF .
31     echo Hello world
32
33 .. The command is found using the current search path in the variable PATH[], which should define an array of directories containing executables.
34
35 コマンドは実行可能コマンドが格納されているディレクトリの配列 ``PATH[]`` 変数の値を用いて探します。
36
37 .. A command may also be prefixed by environment variable definitions.
38
39 コマンドは環境変数の定義によって修正されることがあります。 ::
40
41     # "Hello world" と出力
42     env X="Hello world" Y=2 printenv X
43     # Visual C++ のインクルードパスを検索
44     env include="c:\Program Files\Microsoft SDK\include" cl foo.cpp
45
46 .. _label11.2:
47
48 11.2 検索
49 ----------------------------------
50 .. Commands may contain wildcard patterns. A pattern specifies a set of files through a limited kind of regular expression. Patterns are expanded before the function is executed.
51
52 コマンドにはワイルドカードパターンを含めることができます。パターンには制限された正規表現を用いたファイルの集合を指定します。パターンは関数が実行される前に展開されます。 ::
53
54    # .c 拡張子のファイルをすべてリスト
55    ls *.c
56
57    # 1文字の接頭辞と.cの拡張子を持ったすべてのファイルをリスト
58    ls ?.c
59
60    # hello.mlファイルをfoo.mlにリネーム
61    mv {hello,foo}.ml
62
63 .. A comprehensive description of OMake glob patterns is given in Section 10.4.
64
65 OMakeのglobパターンのさらなる説明は ":ref:`label10.4`" で与えられます。
66
67 .. _label11.3:
68
69 11.3 バックグラウンドでのジョブ
70 ----------------------------------
71 .. The command may also be placed in the background by placing an ampersand after the command. Control returns to the shell without waiting for the job to complete. The job continues to run in the background.
72
73 コマンドはまたアンパサンド ``&`` をコマンドの後に付与することで、バックグラウンド上で実行されます。ユーザへの制御は、ジョブが完了するまで待つことなく返されます。ジョブはバックグラウンド上で走り続けます。 ::
74
75     gcc -o hugeprogram *.c &
76
77 .. index::
78    single: ファイルのリダイレクション
79 .. _label11.4:
80
81 11.4 ファイルのリダイレクション
82 ----------------------------------
83 .. Input and output can be redirected to files by using the <, >, and >& directives after the command.
84
85 入力と出力は ``<`` , ``>`` , ``>&`` をコマンドの後に付与することによって、ファイルにリダイレクトすることができます。 ::
86
87     # "foo" ファイルに書き込み
88     echo Hello world > foo
89
90     # fooファイルからの入力をリダイレクト
91     cat < foo
92
93     # 標準出力、標準エラーをfooファイルにリダイレクト
94     gcc -o boo *.c >& foo
95
96 .. index::
97    single: パイプライン
98 .. _label11.5:
99
100 11.5 パイプライン
101 ----------------------------------
102 .. Pipelines are sequences of commands, where the output from each command is sent to the next. Pipelines are defined with the | and |& syntax. With | the output is redirected, but errors are not. With |& both output and errors are redirected.
103
104 パイプラインはコマンドのシーケンスで、各々のコマンドの出力は次のコマンドへ送られます。パイプは ``|`` と ``|&`` で定義されます。 ``|`` は出力はリダイレクトされますが、エラーはされません。 ``|&`` は出力とエラーの両方がリダイレクトされます。 ::
105
106    # lsコマンドの出力をプリンターに送る
107    ls *.c | lpr
108
109    # 出力とエラーをEメールを使ってjyhに送る
110    gcc -o hugefile *.c |& mail jyh
111
112 .. index::
113    single: 実行の条件分岐
114 .. _label11.6:
115
116 11.6 条件分岐の実行
117 ----------------------------------
118 .. Commands may also be composed though conditional evaluation using the || and && syntax. Every command has an integer exit code, which may be zero or some other integer. A command is said to succeed if its exit code is zero. The expression command1 && command2 executes command2 only if command1 succeeds. The expression command1 || command2 executes command2 only if command1 fails.
119
120 コマンドは ``||`` と ``&&`` の条件分岐を使うことで複雑に組み合わせることができます。すべてのコマンドは0か他の整数の終了コードを返します。コマンドは終了コードが0であった場合、成功したと宣言します。式 ``command1 && command2`` は、 ``command1`` が成功した場合のみ ``command2`` が実行されます。式 ``command1 || command2`` は、 ``command1`` が失敗した場合のみ ``command2`` が実行されます。 ::
121
122    # 可能な場合のみx/yファイルを表示する
123    cd x && cat y
124
125    # foo.exeを実行するか、エラーメッセージを表示する
126    (test -x foo.exe && foo.exe) || echo "foo.exe is not executable"
127
128 .. index::
129    single: グループ化
130 .. _label11.7:
131
132 11.7 グループ化
133 ----------------------------------
134 .. Parenthesis are used for grouping in a pipeline or conditional command. In the following expression, the test function is used to test whether the foo.exe file is executable. If it is, the foo.exe file is executed. If the file is not executable (or if the foo.exe command fails), the message "foo.exe is not executable" is printed.
135
136 パイプラインをグループ化したり、条件分岐をさせる場合には括弧を使います。以下の式では、 ``test`` 関数は ``foo.exe`` ファイルが実行可能であるかどうか試し、もしそうであったのなら、 ``foo.exe`` ファイルが実行されます。もし実行可能でなかったのなら(あるいは ``foo.exe`` コマンドが失敗したのなら)、メッセージ ``"foo.exe is not executable"`` が表示されます。 ::
137
138    # foo.exeを実行するか、エラーメッセージを表示する
139    (test -x foo.exe && foo.exe) || echo "foo.exe is not executable"
140
141 .. _label11.8:
142
143 11.8 シェルコマンドとは何か?
144 ----------------------------------
145 .. Syntactially, shell commands are any line that is not one of the following
146
147 構文的には、シェルコマンドは以下のうち一つも該当していない任意の行を指します。
148
149 .. A variable definition of the form VAR=string
150    A function call f(...) or method call o.f(...)
151    A rule definition containing a colon string: ...
152    A special command, including the following: 
153
154 * ``VAR=string`` の形の変数定義
155 * 関数の呼び出し ``f(...)`` かメソッドの呼び出し ``o.f(...)``
156 * コロン:を含んだルールの定義 ``string: ...``
157 * 以下のリストを含む特殊コマンド
158     * ``if ...``
159     * ``switch ...``
160     * ``match ...``
161     * ``section ...``
162     * ``return ...``
163
164 .. Commands may also be builtin (aliases). See the documentation for the Shell object for more information.
165
166 コマンドはまたビルドイン(エイリアス)でもあります。さらなる情報は ":ref:`label12.1.22`" を参照してください。
167
168 .. _label11.9:
169
170 11.9 基本的なビルドイン関数
171 ----------------------------------
172
173 .. index::
174    single: echo()
175 .. _label11.9.1:
176
177 11.9.1 echo
178 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
179 .. The echo function prints a string.
180
181 ``echo`` 関数は文字列を表示します。 ::
182
183   $(echo <args>)
184   echo <args>
185
186 .. index::
187    single: cd()
188 .. _label11.9.2:
189
190 11.9.2 cd
191 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
192 .. The cd function changes the current directory.
193
194 ``cd`` 関数はカレントディレクトリを変更します。 ::
195
196     cd(dir)
197        dir : Dir
198
199 .. The cd function also supports a 2-argument form:
200
201 ``cd`` 関数は2つの引数を取ることもできます。 ::
202
203     $(cd dir, e)
204        dir : Dir
205        e : expression
206
207 .. In the two-argument form, expression e is evaluated in the directory dir. The current directory is not changed otherwise.
208
209 2つ引数を取る形では、式 ``e`` がディレクトリ ``dir`` 上で評価されます。カレントディレクトリは変更されません。
210
211 .. The behavior of the cd function can be changed with the CDPATH variable, which specifies a search path for directories. This is normally useful only in the osh command interpreter.
212
213 ``cd`` 関数のふるまいはディレクトリの検索パスを指定している ``CDPATH`` 変数を用いて変更できます。これは通常、oshコマンドインタープリタ上でのみ有効です。 ::
214
215     CDPATH : Dir Sequence
216
217 .. For example, the following will change directory to the first directory ./foo, ~/dir1/foo, ~/dir2/foo.
218
219 例えば、以下の式ではディレクトリを最初のディレクトリ ``./foo`` , ``~/dir1/foo`` , ``~/dir2/foo`` に変更します。 ::
220
221     CDPATH[] =
222        .
223        $(HOME)/dir1
224        $(HOME)/dir2
225     cd foo
226
227 .. _label11.10:
228
229 11.10 ジョブを制御するビルドイン関数
230 ---------------------------------------
231
232 .. index::
233    single: jobs()
234 .. _label11.10.1:
235
236 11.10.1 jobs
237 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
238 .. The jobs function prints a list of jobs.
239
240 ``jobs`` 関数はジョブのリストを表示します。 ::
241
242   jobs
243
244 .. index::
245    single: bg()
246 .. _label11.10.2:
247
248 11.10.2 bg
249 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
250 .. The bg function places a job in the background.
251
252 ``bg`` 関数はバックグラウンド上にジョブを配置します。 ::
253
254   bg <pid...>
255
256 .. index::
257    single: fg()
258 .. _label11.10.3:
259
260 11.10.3 fg
261 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
262 .. The fg function brings a job to the foreground.
263
264 ``fg`` 関数はジョブをフォアグラウンドに持っていきます。 ::
265
266   fg <pid...>
267
268 .. index::
269    single: stop()
270 .. _label11.10.4:
271
272 11.10.4 stop
273 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
274 .. The stop function suspends a job.
275
276 ``stop`` 関数はジョブを停止(suspends)します。 ::
277
278   stop <pid...>
279
280 .. index::
281    single: wait()
282 .. _label11.10.5:
283
284 11.10.5 wait
285 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
286 .. The wait function waits for a job to finish. If no process identifiers are given, the shell waits for all jobs to complete.
287
288 ``wait`` 関数はジョブが完了するまで待機します。プロセス固有の値が指定されなかった場合、シェルはすべてのジョブが完了するまで待機します。 ::
289
290   wait <pid...>
291
292 .. index::
293    single: kill()
294 .. _label11.10.6:
295
296 11.10.6 kill
297 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
298 .. The kill function signals a job.
299
300 ``kill`` 関数はジョブにシグナルを送ります。 ::
301
302   kill [signal] <pid...>
303
304 .. _label11.11:
305
306 11.11 コマンド履歴
307 ----------------------------------
308
309 .. index::
310    single: history()
311 .. _label11.11.1:
312
313 11.11.1 history
314 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
315 ::
316
317     $(history-index) : Int
318     $(history) : String Sequence
319     history-file : File
320     history-length : Int
321
322 .. The history variables manage the command-line history in osh. They have no effect in omake.
323
324 ヒストリ変数はosh上のコマンドライン履歴を管理します。これらの変数はomakeに影響を及ぼしません。
325
326 .. The history-index variable is the current index into the command-line history. The history variable is the current command-line history.
327
328 ``history-index`` 変数はコマンドライン履歴における、現在のインデックスを表します。 ``history`` 変数は現在のコマンドライン履歴を表します。
329
330 .. The history-file variable can be redefined if you want the command-line history to be saved. The default value is ~/.omake/osh_history.
331
332 コマンドライン履歴を保存したいと思った場合、あなたは ``history-file`` 変数を再定義することができます。デフォルトの値は ``~/.omake/osh_history`` です。
333
334 .. The history-length variable can be redefined to specify the maximum number of lines in the history that you want saved. The default value is 100. 
335
336 コマンドライン履歴の行数の最大値を指定したい場合、あなたは ``history-length`` 変数を再定義することができます。デフォルトの値は ``100`` です。