<?xml version="1.0" encoding="UTF-8" ?>
<feed xml:lang="ja" xmlns="http://www.w3.org/2005/Atom">
	<generator uri="http://nucleuscms.org/" version="Nucleus CMS v3.31SP1-kes">Nucleus CMS v3.31SP1-kes</generator>

	<id>http://fireball.loafer.jp/kes/</id>
	<link rel="self" type="application/atom+xml" href="http://fireball.loafer.jp/kes/atom.xml" />
	<link rel="related" type="text/html" href="http://fireball.loafer.jp/" />
	<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/" />

	<rights>© 2008 Project Loafer/Project Fireball and all blog writers.</rights>

	<title>Entering Passive Mode</title>
	<subtitle>やる気のない受け身なブログ。実験場。</subtitle>

	<updated>2006-03-31T21:41:00+09:00</updated>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Windows" scheme="http://fireball.loafer.jp/kes/windows/" />
		<content type="html">
<![CDATA[
<p>
shebang の行かどうかは、<br />
先頭が#! で開始しているかどうかを調べればいい。
</p>
<p>
if &quot;%SHEBANG:~0,2%&quot; == &quot;#!&quot; echo SHEBANG!
</p>
<p>
ただ、一昨日のプログラムでは、<br />
for によって特殊変数に行を読み込んでいたため、<br />
そのままでは文字列の部分比較ができない。<br />
そのため、一度普通の変数に格納する必要がある。
</p>
<p>
set SHEBANG=%s
</p>
<a href="http://fireball.loafer.jp/kes/windows/article_109.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/windows/article_109.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/windows/article_109.html" />
		<published>2006-03-31T21:41:00+09:00</published>
		<title type="html"><![CDATA[shebang の解析と実行]]></title>
		<updated>2006-03-31T21:41:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Windows" scheme="http://fireball.loafer.jp/kes/windows/" />
		<content type="html">
<![CDATA[
<p>
さて、昨日は読み込んだ行を出力しただけだったが、<br />
shebang を調べるためには、<br />
行の内容を解析する必要がある。
</p>
<p>
しかし、コマンドプロセッサでは、<br />
変数に対して行える操作は限られている。<br />
特殊変数がもつ、パスの一部分を抜き出す機能は、<br />
数少ない操作の一つである。
</p>
<p>
特殊変数は、コマンド引数や for の引数であるため、<br />
ファイル名に対して使うことが多い。<br />
そのためにそのような機能になっていると考えられる。
</p>
<a href="http://fireball.loafer.jp/kes/windows/article_108.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/windows/article_108.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/windows/article_108.html" />
		<published>2006-03-30T23:58:00+09:00</published>
		<title type="html"><![CDATA[文字列の操作]]></title>
		<updated>2006-03-30T23:58:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Windows" scheme="http://fireball.loafer.jp/kes/windows/" />
		<content type="html">
<![CDATA[
<p>
今日は、ファイルの先頭行を読み出してみよう。
</p>
<p>
Windows 環境には、ファイルの部分行を得るコマンドがない。<br />
Linux などでは、head コマンドが使えるのだが。<br />
仕方ないので、for コマンドを逆用する。
</p>
<p>
for コマンドは、テキストファイルの各行を<br />
トークンに分割する機能があるが、<br />
これを抑止すれば、行単位で繰り返すことができる。
</p>
<p>
for の delims オプションに文字を指定しなければ、<br />
トークンの分割を抑止することができる。<br />
さらに、eol オプションに文字を指定しなければ、<br />
行末までの文字列を全て読み出すことができる。
</p>
<a href="http://fireball.loafer.jp/kes/windows/article_107.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/windows/article_107.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/windows/article_107.html" />
		<published>2006-03-29T21:50:00+09:00</published>
		<title type="html"><![CDATA[ファイルの先頭行を読み出す]]></title>
		<updated>2006-03-29T21:50:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Windows" scheme="http://fireball.loafer.jp/kes/windows/" />
		<content type="html">
<![CDATA[
<p>
括弧がより効果を発揮するのは、<br />
if などを組み合わせた場合だ。
</p>
<p>
if は、条件式の後にコマンドを取るが、<br />
そこに括弧コマンドを使用すると、<br />
以下のような書式が可能となる。
</p>
<p>
if &quot;string&quot;==&quot;string&quot; (<br />
&nbsp; &nbsp; コマンド1<br />
&nbsp; &nbsp; コマンド2<br />
&nbsp; &nbsp; …<br />
)
</p>
<a href="http://fireball.loafer.jp/kes/windows/article_106.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/windows/article_106.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/windows/article_106.html" />
		<published>2006-03-28T22:30:00+09:00</published>
		<title type="html"><![CDATA[括弧と組み合わせる]]></title>
		<updated>2006-03-28T22:30:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Windows" scheme="http://fireball.loafer.jp/kes/windows/" />
		<content type="html">
<![CDATA[
<p>
括弧には、コマンド終端を明確にする役割以外に、<br />
複数のコマンドをまとめる役割もある。
</p>
<p>
開き括弧はコマンドの一種であり、<br />
コマンドを書く場所であればどこでも利用できる。
</p>
<p>
コマンドプロセッサが開き括弧を見つけた場合、<br />
コマンド行を記憶するモードに入る。<br />
その後のコマンドは、記憶されるがすぐに実行はされない。
</p>
<p>
閉じ括弧が見つかった時点で、<br />
今まで入力されたコマンドが一気に実行される。
</p>
<a href="http://fireball.loafer.jp/kes/windows/article_105.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/windows/article_105.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/windows/article_105.html" />
		<published>2006-03-27T19:18:00+09:00</published>
		<title type="html"><![CDATA[「括弧」コマンド]]></title>
		<updated>2006-03-27T19:18:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Windows" scheme="http://fireball.loafer.jp/kes/windows/" />
		<content type="html">
<![CDATA[
<p>
今日は if コマンド。<br />
プログラミングの経験者は、コマンドの名前だけで<br />
このコマンドの役割は分かると思う。
</p>
<p>
if コマンドは条件による分岐を行う。<br />
コマンドプロンプト上で実行する場合はあまり使わないが、<br />
バッチファイル上では、処理の分岐に使う事が多い。
</p>
<p>
if 文の構文は以下の通り。
</p>
<p>
if string==string コマンド<br />
if &quot;string&quot;==&quot;string&quot; コマンド
</p>
<a href="http://fireball.loafer.jp/kes/windows/article_104.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/windows/article_104.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/windows/article_104.html" />
		<published>2006-03-26T22:54:00+09:00</published>
		<title type="html"><![CDATA[if コマンド]]></title>
		<updated>2006-03-26T22:54:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Windows" scheme="http://fireball.loafer.jp/kes/windows/" />
		<content type="html">
<![CDATA[
<p>
バッチファイルのコマンド引数や、<br />
for 文に渡される変数は、% の後に 1 文字続く形である。<br />
これらの変数は特殊変数と呼ばれる。
</p>
<p>
%0 はバッチファイルの名前を意味し、<br />
%1 はバッチファイルの 1 つめの引数、<br />
%9 はバッチファイルの 9 つめの引数だ。<br />
%* は元の引数を分解せずにそのまま保持している。
</p>
<p>
これら特殊変数には、~ と組み合わせることによって、<br />
ファイル名の部分展開の機能があることは前に説明した。
</p>
<a href="http://fireball.loafer.jp/kes/windows/article_103.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/windows/article_103.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/windows/article_103.html" />
		<published>2006-03-25T16:22:00+09:00</published>
		<title type="html"><![CDATA[特殊変数と変数]]></title>
		<updated>2006-03-25T16:22:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Windows" scheme="http://fireball.loafer.jp/kes/windows/" />
		<content type="html">
<![CDATA[
<p>
今日は、for コマンドの /f スイッチをやろう。
</p>
<p>
/f スイッチは非常に特殊で、<br />
テキストファイルの内容や文字列、<br />
そしてコマンドの実行結果に対して、<br />
一行ずつ繰り返しを実行することができる。
</p>
<p>
構文は以下の通り。
</p>
<p>
「for /f &quot;オプション&quot; 変数 in (対象) do 繰り返しコマンド」 
</p>
<a href="http://fireball.loafer.jp/kes/windows/article_102.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/windows/article_102.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/windows/article_102.html" />
		<published>2006-03-24T23:25:00+09:00</published>
		<title type="html"><![CDATA[for コマンド（続き）]]></title>
		<updated>2006-03-24T23:25:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Windows" scheme="http://fireball.loafer.jp/kes/windows/" />
		<content type="html">
<![CDATA[
<p>
cmd には、for というコマンドがある。<br />
for は、ディレクトリ内にあるファイルに対して<br />
繰り返しを行うコマンドだ。
</p>
<p>
cmd で試してみよう。<br />
まずはコマンドプロンプトを起動する。<br />
そして、カレントディレクトリを C:\WINDOWS にする。
</p>
<p>
C:\Documents and Settings\kes&gt;cd \WINDOWS
</p>
<p>
さて、for コマンドを実行してみる。<br />
実行すると、C:\WINDOWS 配下のテキストファイルの名前が<br />
ずらっと表示されたはずだ。
</p>
<a href="http://fireball.loafer.jp/kes/windows/article_101.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/windows/article_101.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/windows/article_101.html" />
		<published>2006-03-23T23:40:00+09:00</published>
		<title type="html"><![CDATA[for コマンド]]></title>
		<updated>2006-03-23T23:40:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="Windows" scheme="http://fireball.loafer.jp/kes/windows/" />
		<content type="html">
<![CDATA[
<p>
Shebang を処理するためには、<br />
どこかのプログラムがまずはスクリプトを開き、<br />
一行目を読んで処理系のパスを調べ、<br />
そのパスにスクリプトを渡して起動する必要がある。
</p>
<p>
どこかのプログラムと言うのが、通常はシェルなのだが、<br />
Windows では Apache などを介する必要があり面倒だ。
</p>
<p>
さて、専用のプログラムを作るのは簡単だが、<br />
今日はあえてバッチファイルで作ってみよう。
</p>
<a href="http://fireball.loafer.jp/kes/windows/article_100.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/windows/article_100.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/windows/article_100.html" />
		<published>2006-03-22T23:38:00+09:00</published>
		<title type="html"><![CDATA[バッチファイル]]></title>
		<updated>2006-03-22T23:38:00+09:00</updated>
	</entry>

</feed>
