This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [cygwin]bash question, perhaps problem


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]