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

[linux-users:106107] Re: #!で始まるスクリプト


SUZUKI Yasuhiro wrote:
> スクリプトファイルをコマンドラインなどで実行する際に、
> まず初めに処理するのは、相変わらずシェルではないでしょうか?
> # execve()で、スクリプトファイルを直接実行
> # 可能であるとは知りませんでしたが。

十分な試験環境がないので、
手許の FC3 という以外の条件がはっきりしない環境での試行ですが、

[kusune@station ~]$ cat ./test.cat
#!/bin/cat -nE

test   file.
[kusune@station ~]$ ./test.cat -b
     1  #!/bin/cat -nE$
$
     2  test   file.$
[kusune@station ~]$ ./test.cat
     1  #!/bin/cat -nE$
     2  $
     3  test   file.$
[kusune@station ~]$ strace bash -c './test.cat -b' 2>&1 >/dev/null | grep execv
execve("/bin/bash", ["bash", "-c", "./test.cat -b"], [/* 25 vars */]) = 0
execve("./test.cat", ["./test.cat", "-b"], [/* 25 vars */]) = 0
[kusune@station ~]$ 

となり、bash が解釈してる形跡はないようにみえますね。

以下にひととおりつけておきます。
strace の出力も確認しましたけど長いのでやめておきますね。
気になる方はご自分の環境でもお試し下さい。
# 不要な試行の結果を削除したりしたので編集ミスがあるかも。
--
Takeshi Kusune <kusune@xxxxxxxxxxxxxx>

[kusune@station ~]$ echo $BASH_VERSION
3.00.14(1)-release
[kusune@station ~]$ uname -a
Linux station.east.group.gr.jp 2.6.11-1.35_FC3 #1 Mon Jun 13 00:52:18 EDT 2005 i586 i586 i386 GNU/Linux
[kusune@station ~]$ cat ./test.cat
#!/bin/cat -nE

test   file.
[kusune@station ~]$ ./test.cat
     1  #!/bin/cat -nE$
     2  $
     3  test   file.$
[kusune@station ~]$ ./test.cat -b
     1  #!/bin/cat -nE$
$
     2  test   file.$
[kusune@station ~]$ strace bash -c './test.cat -b' 2>&1 >/dev/null | grep execv
execve("/bin/bash", ["bash", "-c", "./test.cat -b"], [/* 25 vars */]) = 0
execve("./test.cat", ["./test.cat", "-b"], [/* 25 vars */]) = 0
[kusune@station ~]$ cat ./test2.cat
#!/bin/cat -n -E

test   file.
[kusune@station ~]$ ./test2.cat
/bin/cat: invalid option --
Try `/bin/cat --help' for more information.
[kusune@station ~]$ ./test2.cat -b
/bin/cat: invalid option --
Try `/bin/cat --help' for more information.
[kusune@station ~]$ strace bash -c './test2.cat -b' 2>&1 >/dev/null | grep execv
execve("/bin/bash", ["bash", "-c", "./test2.cat -b"], [/* 25 vars */]) = 0
execve("./test2.cat", ["./test2.cat", "-b"], [/* 25 vars */]) = 0
[kusune@station ~]$

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

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