delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/06/26/09:30:59

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/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: <5.1.0.14.2.20020626062010.01b43240@pop3.cris.com>
X-Sender: rrschulz AT pop3 DOT cris DOT com
Date: Wed, 26 Jun 2002 06:29:51 -0700
To: "bruno patin" <bruno DOT patin AT wanadoo DOT fr>, "Cygwin" <cygwin AT cygwin DOT com>
From: Randall R Schulz <rrschulz AT cris DOT com>
Subject: Re: [cygwin]bash question, perhaps problem
In-Reply-To: <001101c21c82$af12b440$022b01c0@patin>
Mime-Version: 1.0

Bruno,

This is not a bug.

It has never been proper to examine $0 / argv[0] to determine anything 
about the current working directory in which a command was invoked.

In scripts, that's what "pwd" (built-in) or "/bin/pwd" (executable) is for. 
Unless something in the ".bashrc" file is changing the current directory (a 
very dubious practice), the current working directory at the time the 
script's commands begin executing will be the same as that in which the 
script was invoked.

Perhaps I misunderstand your words. I you want to know where the invoked 
script is located based on $0, you can (in BASH only) use this:

scriptDir="${0%/*}"

For details of this and related variable expansion / substitution syntax, 
see the section titled "Shell Parameter Expansion" in the BASH manual 
(simply "Parameter Expansion" in the BASH man page).

Randall Schulz
Mountain View, CA USA


At 12:58 2002-06-25, bruno patin wrote:

>if you consider the simple script
>
>---------------------
>#!/bin/bash
>echo $0
>-----------------------
>
>the line do give normally the exact text you use to execute the command
>(see the man pages of bash). but, on cygwin, we have, when executed from
>a distant directory by a relative call, the absolute name. So we can't
>use this name to return from the local directory to where this command
>was launched.
>
>is it a known bug, is it nominal ?
>
>thanks for your great work


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.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