From owner-freebsd-questions@FreeBSD.ORG Tue Feb 12 15:14:45 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 77457231 for ; Tue, 12 Feb 2013 15:14:45 +0000 (UTC) (envelope-from Devin.Teske@fisglobal.com) Received: from mx1.fisglobal.com (mx1.fisglobal.com [199.200.24.190]) by mx1.freebsd.org (Postfix) with ESMTP id 496DDA4C for ; Tue, 12 Feb 2013 15:14:44 +0000 (UTC) Received: from smtp.fisglobal.com ([10.132.206.16]) by ltcfislmsgpa04.fnfis.com (8.14.5/8.14.5) with ESMTP id r1CFEcMV025608 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Tue, 12 Feb 2013 09:14:38 -0600 Received: from LTCFISWMSGMB21.FNFIS.com ([10.132.99.23]) by LTCFISWMSGHT05.FNFIS.com ([10.132.206.16]) with mapi id 14.02.0309.002; Tue, 12 Feb 2013 09:14:37 -0600 From: "Teske, Devin" To: "tundra@tundraware.com" , FreeBSD Mailing List Subject: RE: Was I Sourced? Thread-Topic: Was I Sourced? Thread-Index: AQHOCTDkxdyuJ9XV602x2PyC2sZ4vJh2UURr Date: Tue, 12 Feb 2013 15:14:37 +0000 Message-ID: <13CA24D6AB415D428143D44749F57D7201EA755A@ltcfiswmsgmb21> References: <511A5771.9020208@tundraware.com> In-Reply-To: <511A5771.9020208@tundraware.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.132.253.120] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.9.8327, 1.0.431, 0.0.0000 definitions=2013-02-12_05:2013-02-12,2013-02-12,1970-01-01 signatures=0 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Feb 2013 15:14:45 -0000 On Tue, 12 Feb 2013, Tim Daneliuk wrote: > Is there a way for script to determine whether is was sourced > or forked off as a subprocess when it was invoked? >=20 Not that I'm aware of. > I have a script that needs to be sourced to work properly and > I want to warn the luser if they exec or subshell it instead. >=20 In order for a user to exec a script it has to have the invocation line: #!/bin/sh So naturally, if your script is missing this as the first line, the file wi= ll not be interpretable (and thus exec will fail). And if the file is not e= xecutable (due to lack of invocation line) then you also shouldn't have any= worry about execution within a sub-shell (though it will still be possible= to "source" within a sub-shell using "." -- but that shouldn't be any diff= erent than sourcing in the main shell). One thin you could do is to use an invocation line that will warn the user = that it shouldn't be executed directly... #!/not_directly_executable # Use the source luke So when someone executes your script they get... -bash: ./script: /not_directly_executable: bad interpreter: No such file or= directory --=20 Devin _____________ The information contained in this message is proprietary and/or confidentia= l. If you are not the intended recipient, please: (i) delete the message an= d all copies; (ii) do not disclose, distribute or use the message in any ma= nner; and (iii) notify the sender immediately. In addition, please be aware= that any message addressed to our domain is subject to archiving and revie= w by persons other than the intended recipient. Thank you.