From owner-freebsd-questions@FreeBSD.ORG Tue Feb 12 18:41:20 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 AEB9FF35 for ; Tue, 12 Feb 2013 18:41:20 +0000 (UTC) (envelope-from tundra@tundraware.com) Received: from ozzie.tundraware.com (ozzie.tundraware.com [75.145.138.73]) by mx1.freebsd.org (Postfix) with ESMTP id 57A0D9BC for ; Tue, 12 Feb 2013 18:41:20 +0000 (UTC) Received: from [10.219.130.158] ([66.175.245.1]) (authenticated bits=0) by ozzie.tundraware.com (8.14.6/8.14.6) with ESMTP id r1CIf6lQ018624 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Tue, 12 Feb 2013 12:41:07 -0600 (CST) (envelope-from tundra@tundraware.com) Message-ID: <511A8CEC.3060007@tundraware.com> Date: Tue, 12 Feb 2013 12:41:48 -0600 From: Tim Daneliuk Organization: TundraWare Inc. User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: FreeBSD Mailing List Subject: Re: Was I Sourced? References: <201302121710.r1CHAlNh028236@mail.r-bonomi.com> In-Reply-To: <201302121710.r1CHAlNh028236@mail.r-bonomi.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (ozzie.tundraware.com [75.145.138.73]); Tue, 12 Feb 2013 12:41:07 -0600 (CST) X-TundraWare-MailScanner-Information: Please contact the ISP for more information X-TundraWare-MailScanner-ID: r1CIf6lQ018624 X-TundraWare-MailScanner: Found to be clean X-TundraWare-MailScanner-From: tundra@tundraware.com X-Spam-Status: No X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: tundra@tundraware.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Feb 2013 18:41:20 -0000 On 02/12/2013 11:10 AM, Robert Bonomi wrote: >> Date: Tue, 12 Feb 2013 08:53:37 -0600 >> From: Tim Daneliuk >> To: FreeBSD Mailing List >> Subject: Was I Sourced? >> >> Is there a way for script to determine whether is was sourced >> or forked off as a subprocess when it was invoked? >> >> 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. > > a 'sourced' script does -not- honor a shebag line. > you can exploit that. > > The executable script /usr/local/bin/source_only; > #!/bin/sh > echo Error: this script must be sourced > > Your script: > #!/usr/local/bin/source_only > > {cmd} > {cmd} > {cmd} > {cmd} > {cmd} > {cmd} > ... > ... > > Trying to do it totally self-contained is not easy. > > Actually, it's not that hard. Setting the shebang line to this does the trick: #!/bin/echo "This Script Must Be Sourced!!!!" Thanks to all who replied on this one ... -- ----------------------------------------------------------------------- Tim Daneliuk