From owner-freebsd-questions Sat Feb 8 7:44:15 2003 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B230C37B405 for ; Sat, 8 Feb 2003 07:44:13 -0800 (PST) Received: from groggy.anc.acsalaska.net (groggy.anc.acsalaska.net [208.151.119.232]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3B2AC43FBD for ; Sat, 8 Feb 2003 07:44:11 -0800 (PST) (envelope-from abc@anchorageinternet.org) Received: from en26.groggy.anc.acsalaska.net (root@printer [192.168.0.26]) by groggy.anc.acsalaska.net (8.12.6/8.12.6) with ESMTP id h18Fi17X012310 for ; Sat, 8 Feb 2003 06:44:01 -0900 (AKST) (envelope-from abc@anchorageinternet.org) Received: (from abc@localhost) by en26.groggy.anc.acsalaska.net (8.12.6/8.12.6) id h18FiPTu024398 for "freebsd-questions" ; Sat, 8 Feb 2003 15:44:25 GMT (envelope-from abc@anchorageinternet.org) Date: Sat, 8 Feb 2003 15:44:25 GMT From: abc@anchorageinternet.org Message-Id: <200302081544.h18FiPTu024398@en26.groggy.anc.acsalaska.net> X-Authentication-Warning: en26.groggy.anc.acsalaska.net: abc set sender to abc@anchorageinternet.org using -f Subject: #!/bin/sh & execve X-Mailer: Umail v2.9.2 To: "freebsd-questions" Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG say i have 2 scripts, scriptA and scriptB. scriptA ------- #!/bin/sh ./scriptB 1 2 3 scriptB ------- #!/bin/sh echo 0:$0 echo 1:$1 echo 2:$2 echo 3:$3 -- $ ./scriptA $0:./scriptB $1:1 $2:2 $3:3 -- according to execve(2), only a single [arg] should be recognized: #! interpreter [arg] When an interpreter file is execve'd, the system actually execve's the specified interpreter. If the optional arg is specified, it becomes the first argument to the interpreter, and the name of the originally execve'd file becomes the second argument; otherwise, the name of the originally execve'd file becomes the first argument. The original argu- ments are shifted over to become the subsequent arguments. The zeroth argument is set to the specified interpreter. so the argv[] array in execve() should be loaded as: argv[0]=sh, argv[1]=scriptB, argv[2]=scriptA, and argv[3...]=command line args passed to scriptA. i read many many execve() man pages, and it seems like this is the way things should be. but in practice, it appears on many unix's, argv[] gets loaded additionally with any options given to a script (which is given as the "[arg]" to the interpreter) on the 1st line of a script. can anyone tell me if this is "proper", and why or why not? there doesn't seem to be consistency across unix's. some ignore, or give an error if more than one "[arg]" exists on the 1st line of a script. thank you. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message