牧野です。
In message [linux-users:20586] Re: シェルスクリプトについて,
Takashi Ishioka <ishioka _at_ dad.eec.toshiba.co.jp> said:
>なんか, コマンドを入れとくバッファのサイズが限られてるって感じです.
>SunOS は とくに短いような...
>
>ためしに, Linux で...(tcsh ね)
>#!/bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/../bin/..\/bin/../bin/../bin/../bin/../bin/../bin/echo a b c
>
>ってのでやると,
>
>./bbb
>a b ./bbb
>
>もういっこ増やすと, command not found
>もっとふやすと Permission denied
>
>となってたのしいです(^^;
結構楽しいですね (^^;
argcheck.c:
--
#include <stdio.h>
void
main(int argc,char *argv[]) {
int i;
for (i = 0; i < argc; i++) {
printf("argv[%d] = %s\n", i, argv[i]);
}
exit (0);
}
--
の様なのを作って、
mfoo:
--
#! ./argcheck a b c
--
% ./mfoo
argv[0] = argcheck
argv[1] = a b c
argv[2] = ./mfoo
mfoo:
--
#! ./argcheck 123456789 _at_ 123456789@123456789 _at_ 123456789@123456789 _at_ 123456789@123456
789 _at_ 123456789@123456789 _at_ 123456789@123456789 _at_ 123456789@123456789@
--
だと
% ./mfoo
argv[0] = argcheck
argv[1] = 123456789 _at_ 123456789@123456789 _at_ 123456789@123456789 _at_ 123456789@123456789 _at_ 123456789@123456789 _at_ 123456789@123456789 _at_ 123
argv[2] = ./mfoo
ふむ、ふむ。
#! の行の中と、
スクリプト内部じゃだいぶ処理が違うようですね。
ここまで来たら、やっぱソースかな。
bash-1.14.7を見ると、execute_cmd.cの、
shell_execve (command, args, env)の中に、
:
:
{
unsigned char sample[80];
int sample_len = read (fd, &sample[0], 80);
close (fd);
if (sample_len == 0)
return (EXECUTION_SUCCESS);
/* Is this supposed to be an executable script?
If so, the format of the line is "#! interpreter [argument]".
A single argument is allowed. The BSD kernel restricts
the length of the entire line to 32 characters (32 bytes
being the size of the BSD exec header), but we allow 80
characters. */
if (sample_len > 0 && sample[0] == '#' && sample[1] == '!')
return (execute_shell_script
(sample, sample_len, command, args, env));
てなことが書いてあったりする。
BUFSIZ位取ってくれてもいいような気もするけど、
引数は1個限定だし...(複数書いても、1個に固まる)
過去との互換性重視って奴かいな?
-- mac
Follow-Ups:
- [linux-users:20604] Re: シェルス クリプトについてWATANABE Hirofumi
- [linux-users:20586] Re: シェルスクリプトについてTakashi Ishioka
- Prev by Subject: [linux-users:20601] Re: プログラムのバージョンアップについて。
- Next by Subject: [linux-users:20603] Re: シェルスクリプトについて
- Previous by thread: [linux-users:20592] Re: シェルスクリプトについて
- Next by thread: [linux-users:20604] Re: シェルス クリプトについて
- Indexes:[Main][Thread]