[cygwin]bash question, perhaps problem

Randall R Schulz rrschulz@cris.com
Wed Jun 26 07:15:00 GMT 2002


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/



More information about the Cygwin mailing list