delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/02/06/20:46:52

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <4206C87D.2010705@tlinx.org>
Date: Sun, 06 Feb 2005 17:46:37 -0800
From: linda w <cygwin AT tlinx DOT org>
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
MIME-Version: 1.0
To: Arthur Schwarz <aschwarz1309 AT worldnet DOT att DOT net>
CC: cygwin AT cygwin DOT com
Subject: Re: Using PWD
References: <000701c50c70$37411610$713d480c AT arthurfxgimkdx>
In-Reply-To: <000701c50c70$37411610$713d480c@arthurfxgimkdx>
X-IsSubscribed: yes

the 3rd example works with dirname $0 as well.

In your 2nd example there is no script that is running.  The
commands in the script are read as though you typed them in from
the terminal -- which means there is no "scriptname" to find
the name of.

You could check if $0 is equal to a shell name and give an error,
but source <command_list> isn't equivalent to calling a shell
script.

Sorry don't have any better answers for #2...
-linda


Arthur Schwarz wrote:

>I'm trying to find the directory of an executing bash script and am having
>very limited success. For example(s):
>
>1. <path>/script.sh
>2. source <path>/script.sh
>3. bash <path>/script.sh
>
>I can find the correct <path> only for the first example (dirname $0). PWD
>(of course) only works when <path> == ./. The other two cases I can't seem
>to get to work. Any idea how to get the <path> in examples 2 and 3?
>
>
>  
>


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019