[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

[linux-users:20602] Re: シェルスクリプトについて


牧野です。

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

この情報があなたの探していたものかどうか選択してください。
yes/まさにこれだ!   no/違うなぁ   part/一部見つかった   try/これで試してみる

あなたが探していた情報はどのようなことか、ご自由に記入下さい。特に「まさにこれだ!」と言う場合は記入をお願いします。
例:「複数のマシンからCATV経由でipmasqueradeを利用してWebを参照したい場合の設定について」
Follow-Ups: References: