Section Next | Prev


3.3.8 組込みコマンド機能

built-in コマンドとは、シェルに組み込まれたコマンドで子プロセスを生成せずに直 接シェルが実行するコマンドです。 以下に主な組み込みコマンドを示します。
break
foreach あるいは while ループから抜け出る。

continue
foreach あるいは while ループを始めから繰り返す。

exec [ 引き数 ]
引き数で指定したコマンドを実行する。この時、シェルに制御は戻りません。
	$  exec /bin/ls 
		( 一瞬ファイルの一覧が表示され、端末は失われる )

exit [ n ]
シェル・スクリプトから抜ける。 n は戻り値になる。 n を指定しない時はシェル変数 status の値が返される。

ulimit -オプション [ 値 ]
システム資源の制限を行なう。値を省略すると現在の設定値が表示される。
	$ ulimit -a
	core file size          (blocks, -c) 0
	data seg size           (kbytes, -d) unlimited
	file size               (blocks, -f) unlimited
	pending signals                 (-i) 1024
	max locked memory       (kbytes, -l) 32
	max memory size         (kbytes, -m) unlimited
	open files                      (-n) 2048
	pipe size            (512 bytes, -p) 8
	POSIX message queues     (bytes, -q) 819200
	stack size              (kbytes, -s) 10240
	cpu time               (seconds, -t) unlimited
	max user processes              (-u) 6114
	virtual memory          (kbytes, -v) unlimited
	file locks                      (-x) unlimited

	$ ulimit -c unlimited	# core 生成の許可
	$  cat &
	[1] 3462
	$ kill -ILL 3462	# 強制的に core を生成

	[1]+  Stopped                 cat
	$ fg
	cat
	不正な命令です (core dumped)
	$ ls -l core*
	-rw-------  1 ycos ycos 974848  9月 30 12:10 core.3462

	$ ulimit -c 0		# core 生成の抑制
	$ cat &
	[1] 3464
	$ kill -ILL 3464

	[1]+  Stopped                 cat
	$ fg
	cat
	不正な命令です

nohup
nohup をジョブの先頭に記述すると、ハングアップ・シグナルを無視して実行し 続けます(logout 後も実行を続ける)。 ターミナルから引き数にコマンド名を指定して使用 する時は、そのコマンドはハングアップ・シグナルを無視して実行します。
ログアウトしても実行を継続したい時に使用します。

	$ nohup ping localhost &
	[1] 3553
	$ nohup: appending output to `nohup.out'
	$ exit
		( 一端シェルを終了 )

		( 再度ログインしなおす )
	$ ps ax |grep ping
	 3553 ?        S      0:00 ping localhost
	 3561 pts/1    R+     0:00 grep ping
	# 直前に実行していた ping はまだ継続中
	# また端末(pts/1など)はなく ? として表記されている

	$ tail nohup.out	# 出力結果は nohup.out に保存されている
	64 bytes from localhost (127.0.0.1): icmp_seq=74 ttl=64 time=0.071 ms
	64 bytes from localhost (127.0.0.1): icmp_seq=75 ttl=64 time=0.058 ms
	64 bytes from localhost (127.0.0.1): icmp_seq=76 ttl=64 time=0.105 ms
	64 bytes from localhost (127.0.0.1): icmp_seq=77 ttl=64 time=0.107 ms
	64 bytes from localhost (127.0.0.1): icmp_seq=78 ttl=64 time=0.075 ms
	64 bytes from localhost (127.0.0.1): icmp_seq=79 ttl=64 time=0.073 ms
	64 bytes from localhost (127.0.0.1): icmp_seq=80 ttl=64 time=0.070 ms
	64 bytes from localhost (127.0.0.1): icmp_seq=81 ttl=64 time=0.107 ms
	64 bytes from localhost (127.0.0.1): icmp_seq=82 ttl=64 time=0.060 ms
	64 bytes from localhost (127.0.0.1): icmp_seq=83 ttl=64 time=0.071 ms
	$ kill -9 3553
trap "コマンド..." シグナル...
割り込みシグナルを受けた時に、コマンドを実行します。
	$ trap 'echo GET USR1 signal' 30
	$ trap 'echo GET USR1 signal' USR1
	$ kill -USR1 $$
	GET USR1 signal
シグナルには番号だけでなく、ニーモニックも利用できます。

shift
引き数 $1, $2 ... の値を1つずつずらす。
	$ set - a b c d 
	$ echo $* ; shift
	a b c d
	$ !!
	echo $* ; shift
	b c d
	$ !!
	echo $* ; shift
	c d

. スクリプト名
ドット(.)コマンドは、新しくプロセスを作らずにスクリプトの内容を実行します。 .profile ファイルを変更して再びログインする事もなくカレント・シェルに効果を加え たい時などに使用します。

wait [job]
バッグ・グラウンド・ジョブ終了を待ちます。 引き数がない場合は全てのサブプロセス終了をまちます。
	$ ( date ; sleep 3 ) &  date
	[2]     19776
	1998年06月03日 10時57分04秒
	$ 1998年06月03日 10時57分04秒
 
	$ ( date ; sleep 3 ) & wait ; date
	[2]     19775
	1998年06月03日 10時54分58秒
	1998年06月03日 10時55分01秒


Section Next | Prev

Copyright 2007 ycosSystems Shell/Body338.html