haiku/docs/userguide/jp/bash-scripting.html

112 lines
8.3 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<!--
*
* Copyright 2009, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Humdinger <humdingerb@gmail.com>
* Translators:
* log-1
* mt
*
-->
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="robots" content="all" />
<title>Bash とスクリプト処理</title>
<link rel="stylesheet" type="text/css" href="../Haiku-doc.css" />
</head>
<body>
<div id="banner">
<div><span>User guide</span></div>
</div>
<div class="nav">
<div class="inner">
<ul class="lang-menu">
<li class="now"><img src="../images/flags/jp.png" alt="" /> 日本語</li>
<li><a href="../fr/bash-scripting.html"><img src="../images/flags/fr.png" alt="" />Français</a></li>
<li><a href="../de/bash-scripting.html"><img src="../images/flags/de.png" alt="" />Deutsch</a></li>
<li><a href="../it/bash-scripting.html"><img src="../images/flags/it.png" alt="" />Italiano</a></li>
<li><a href="../ru/bash-scripting.html"><img src="../images/flags/ru.png" alt="" />Русский</a></li>
<li><a href="../es/bash-scripting.html"><img src="../images/flags/es.png" alt="" />Español</a></li>
<li><a href="../sv_SE/bash-scripting.html"><img src="../images/flags/sv_SE.png" alt="" />Svenska</a></li>
<li><a href="../uk/bash-scripting.html"><img src="../images/flags/uk.png" alt="" />Українська</a></li>
<li><a href="../zh_CN/bash-scripting.html"><img src="../images/flags/zh_CN.png" alt="" /> 中文 [中文]</a></li>
<li><a href="../pt_PT/bash-scripting.html"><img src="../images/flags/pt_PT.png" alt="" />Português</a></li>
<li><a href="../fi/bash-scripting.html"><img src="../images/flags/fi.png" alt="" />Suomi</a></li>
<li><a href="../sk/bash-scripting.html"><img src="../images/flags/sk.png" alt="" />Slovenčina</a></li>
<li><a href="../en/bash-scripting.html"><img src="../images/flags/gb.png" alt="" />English</a></li>
</ul>
<span>
«  <a href="preferences.html">Preferences (プレファレンス)</a> 
::  <a href="contents.html" class="uplink">Contents</a> 
<!-- ::  <a href="filesystem-layout.html">ファイルシステムの設計</a>  » -->
</span></div>
</div>
<div id="content">
<div>
<h1>Bash とスクリプト処理</h1>
<p>「スクリプト処理」とは、複数のコマンドを並べて書き、「スクリプト」と呼ばれるテキストファイルとして保存することにより処理を自動化する方法のことです。スクリプトを走らせるたびに、あたかも<a href="applications/terminal.html">ターミナル</a>でそれらコマンドをひとつひとつ手で打ち込んでいるようにコマンドが実行されます。<br />
スクリプトは、単に数個のコマンドをある特定の順番で実行するものから、複雑なタスクを処理するための高度なコードのかたまりまで、多岐にわたります。</p>
<h2>
<a href="#"><img src="../images/up.png" style="border:none;float:right" alt="index" /></a>
<a id="bash" name="bash">Bash</a></h2>
<p>そもそもスクリプトはそれを解釈するシェルに大きく依存するため、まずは Haiku で使用されている BASH に精通する必要があります。BASH は広く使用されているシェルであるため、オンライン上に資料が豊富に存在します。すばらしいドキュメントの 1 つに、Johan Jansson 氏の <a href="http://www.beforever.com/bashtut.htm" class="printurl">Introduction to bash - a tutorial for bash under BeOS</a> があります。</p>
<h2>
<a href="#"><img src="../images/up.png" style="border:none;float:right" alt="index" /></a>
<a id="scripting-bible" name="scripting-bible">スクリプト処理のための必読書</a></h2>
<p>シェル内で作業するためのいくつかの基礎を学んだあとは、スクリプト処理の世界にゆっくりと歩み出しましょう。このときも、本屋と同じくらい豊富なチュートリアルやリファレンスをオンライン上で見つけられるでしょう。Haiku にほぼピッタリの非常にすばらしい入門編に、オンラインで入手可能な Scot Hacker 氏による BeOS の必読書の <a href="http://www.birdhouse.org/beos/bible/bos/ch_scripting1.html" class="printurl">Scripting Chapter</a> (<a href="http://www.birdhouse.org/beos/bible/bos/BeOS.scripting.PDF">PDF, 900kb</a>) があります。</p>
<h2>
<a href="#"><img src="../images/up.png" style="border:none;float:right" alt="index" /></a><a id="user-scripts" name="user-scripts">Haiku におけるスクリプト</a></h2>
<p>Haiku では、当然のことながらシステムもまたスクリプト処理を使用しています。起動とシャットダウンはスクリプト処理手続きの典型です。始めから定義されたこれら手続きは、特定のユーザースクリプトを用いてユーザーが拡張できます。<br />
もしこれらユーザースクリプトがまだ存在しない場合は、手動でこれらファイルを作成する必要があります。ユーザースクリプトが存在する場合は、処理を実行したい場所に必要なコマンドを追加するだけで済みます。</p>
<h3>
<a href="#"><img src="../images/up.png" style="border:none;float:right" alt="index" /></a>
<a id="userbootscript" name="userbootscript">UserBootscript</a></h3>
<p>システムの起動プロセスが完了すると、<span class="path">/boot/home/config/boot/UserBootscript</span> が実行されます。たとえば次のように、システムが起動した直後に毎回いくつかのプログラムを自動起動させることができます:</p>
<pre># ランチャーを起動する
/boot/system/apps/LaunchBox &amp;
# ワークスペースアプレットを起動する
/boot/system/apps/Workspaces &amp;</pre>
<p>コマンドをバックグラウンドプロセスとして実行するために、コマンドの末尾は "<tt>&amp;</tt>" で終わらせることを覚えておいてください。そうしなければ、そのコマンドが完了するまで (この例では、起動したアプリケーションが再度閉じられるまで) スクリプトが停止してしまいます。</p>
<p>システムの起動時にアプリケーションを起動させるための、上記とは違うシンプルな方法の 1 つに、それらアプリケーションへのリンクを <span class="path">/boot/home/config/boot/launch</span> ディレクトリに置くという方法があります。この方法は、自動起動させたいアプリケーションを右クリックして、<span class="menu">指定先にリンクを作成 (Create Link)</span> にマウスカーソルを合わせたあと、前述のディレクトリへ<a href="tracker.html#navigating">ナビゲート</a>することで簡単に実現できます。</p>
<h3>
<a href="#"><img src="../images/up.png" style="border:none;float:right" alt="index" /></a>
<a id="usershutdownscript" name="usershutdownscript">UserShutdownScript</a></h3>
<p><span class="path">/boot/home/config/boot/UserShutdownScript</span> はシャットダウンプロセスの最初のステップで実行されます。このスクリプトが 0 でない終了ステータスを返すと、シャットダウンは中断されます。</p>
<h3>
<a href="#"><img src="../images/up.png" style="border:none;float:right" alt="index" /></a>
<a id="usershutdownfinishscript" name="usershutdownfinishscript">UserShutdownFinishScript</a></h3>
<p><span class="path">/boot/home/config/boot/UserShutdownFinishScript</span> はシャットダウンの最終ステップで実行されます。このスクリプトが実行されるときには、システムの大部分が終了していることに注意してください。</p>
</div>
</div>
<div class="nav">
<div class="inner"><span>
«  <a href="preferences.html">Preferences (プレファレンス)</a> 
::  <a href="contents.html" class="uplink">Contents</a> 
<!-- ::  <a href="filesystem-layout.html">ファイルシステムの設計</a>  » -->
</span></div>
</div>
</body>
</html>