Re: Strange UNIX or strange IDL? [message #13344] |
Mon, 09 November 1998 00:00 |
Vap User
Messages: 31 Registered: April 1998
|
Member |
|
|
LC's No-Spam Newsreading account <nospam@ifctr.mi.cnr.it> writes:
> On 6 Nov 1998, Vap User wrote:
>
>> Harald Frey <hfrey@ssl.berkeley.edu> writes:
>>
>> returns a null string if there there isn't. PWD is always defined in
>> the Cshell (not sure about sh, but I think it must be true for it as
>
> not in mine (DU 3.2)
>
>> 'pwd' is a *command* in the cshell that returns the *value* of the
>> environmental variable 'PWD'. 'PWD' is not any command -unless you are
>
> Yes, pwd is the command, but the variable is called 'cwd'.
> pwd is the same as "echo $cwd"
> And 'cwd' is a shell variable (in csh use command "set" to see them)
> and not an environment variable (in chs use "printenv"). And since
> is not in the environment (of the parent process of IDL) IDL won't getenv
> it.
Actually, in the cshell, the PWD environmental variable is updated
everytime the cwd shell variable changes. See 'setenv' in
csh(1). However, this information doesn't help us in our current
problem, although I thought it did, until a short while ago.
> And also remember that within IDL you can CD to a different directory
> without any effect on the shell.
>
But not without effect on where files get written, for instance.
> So consider the two (IDL and shell)
> fully disjoint environments.
>
Boy, am I glad I messed around with this for a moment or two. I was
about to shoot myself in the foot, bigtime.
I think I have a handle on this now. It turns out that neither of us
are completely right, though Harald had a more *functionally*
complete understanding that I. I don't think it has anything to do
with which shell you're using or the way shells keep track of
PWD.. Since IDL is a compiled program, and is exec'd (if not
fork/exec'd) it has to keep track of the current working directory,
defined in my 'C A Reference Manual' as the directory where default
output will occur, and it does this. It even makes this information
available via 'cd,cur=cur & print,cur' should we want it. It just
doesn't update the PWD environmental variable, the way you can in
Perl when using the 'chdir' of the 'Cwd' module.
This problem arrises because PWD is the one of the few, if not the
only, environmental variables that are mutable over short time spans,
unlike say, USER.
While it is useful to have a handle on how environmental variables
are affected while in IDL, since this discussion started with the
question of how to get the current working directory, the best
suggestion remains...
pro pwd
cd,cur=cur & print,cur
end
This should work whatever the machine, whatever the shell.
whd
> --
> ------------------------------------------------------------ ----------
> nospam@ifctr.mi.cnr.it is a newsreading account used by more persons to
> avoid unwanted spam. Any mail returning to this address will be rejected.
> Users can disclose their e-mail address in the article if they wish so.
>
--
I don't speak for JPL, it doesn't speak for me.
Well, not all the time, at least.
William Daffer <vapuser@haifung.jpl.nasa.gov>
|
|
|
Re: Strange UNIX or strange IDL? [message #13366 is a reply to message #13344] |
Fri, 06 November 1998 00:00  |
LC's No-Spam Newsread
Messages: 18 Registered: September 1997
|
Junior Member |
|
|
On 6 Nov 1998, Vap User wrote:
> Harald Frey <hfrey@ssl.berkeley.edu> writes:
>
> returns a null string if there there isn't. PWD is always defined in
> the Cshell (not sure about sh, but I think it must be true for it as
not in mine (DU 3.2)
> 'pwd' is a *command* in the cshell that returns the *value* of the
> environmental variable 'PWD'. 'PWD' is not any command -unless you are
Yes, pwd is the command, but the variable is called 'cwd'.
pwd is the same as "echo $cwd"
And 'cwd' is a shell variable (in csh use command "set" to see them)
and not an environment variable (in chs use "printenv"). And since
is not in the environment (of the parent process of IDL) IDL won't getenv
it.
And also remember that within IDL you can CD to a different directory
without any effect on the shell. So consider the two (IDL and shell)
fully disjoint environments.
--
------------------------------------------------------------ ----------
nospam@ifctr.mi.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.
|
|
|
Re: Strange UNIX or strange IDL? [message #13367 is a reply to message #13366] |
Fri, 06 November 1998 00:00  |
Vap User
Messages: 31 Registered: April 1998
|
Member |
|
|
Harald Frey <hfrey@ssl.berkeley.edu> writes:
> IDL> print,!version
> { sparc sunos unix 5.1 Apr 13 1998}
> IDL> pwd=getenv('PWD')
> IDL> print,pwd
> /disks/sprite/disk1/hfrey/idl/image/wic
> IDL> pwd=getenv('pwd')
> IDL> print,pwd
>
> IDL>
>
Getenv returns the value of the input argument, provided there is an
environmental variable currently defined matching that argument. It
returns a null string if there there isn't. PWD is always defined in
the Cshell (not sure about sh, but I think it must be true for it as
well). These environmental variables are, by convention,
uppercase. Getenv('pwd') returns null because the evnrionmental
variable is 'PWD', not 'pwd'.
> With the name argument of getenv set to capital letters I get the right
> answer, but in small letters 'pwd' returns the null string. However, if
> I use the same command on the UNIX platform I get
>
> image1 [1] pwd
> /disks/sprite/disk1/hfrey/idl/image/wic
> image1 [2] PWD
> PWD: Command not found
>
> and UNIX does not like the capital letter 'PWD'.
>
> Any explanation?
>
'pwd' is a *command* in the cshell that returns the *value* of the
environmental variable 'PWD'. 'PWD' is not any command -unless you are
unwise enough to have to have a shell script or binary in your path
with that name - so attempting to execute it at the command line will
result in complaints from the shell.
> Harald Frey
> hfrey@ssl.berkeley.edu
>
All of this is very unix-centric and will probably not work on a
non-unix machine. If you want portable code, try...
pro pwd
cd,current=current & print,current
end
which should work whatever the platform.
--
I don't speak for JPL, it doesn't speak for me.
Well, not all the time, at least.
William Daffer <vapuser@haifung.jpl.nasa.gov>
|
|
|
Re: Strange UNIX or strange IDL? [message #13391 is a reply to message #13366] |
Thu, 05 November 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
David Kastrup (dak@neuroinformatik.ruhr-uni-bochum.de) writes:
> If you are really just tying to get the current working
> directory, here is an IDL program for you:
>
> PRO PWD
> CD, Current=thisDirectory
> Print, thisDirectory
> END
>
> Wouldn't know how to get along without it. :-)
> What's wrong with
> IDL> $pwd
Too UNIX-centric. I like cross-platform solutions in my
line of work. :-)
Cheers,
David
----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438, Toll-Free Book Orders: 1-888-461-0155
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
|
Re: Strange UNIX or strange IDL? [message #13410 is a reply to message #13391] |
Wed, 04 November 1998 00:00  |
seanosea
Messages: 6 Registered: November 1998
|
Junior Member |
|
|
In unix, roughly speaking, pwd returns the environment variable $PWD,
available to all processes.
The IDL command getenv('PWD') asks directly for the environment variable.
Unless you've issued system calls, this is the directory IDL was started from.
This is *not* the same as the current directory which IDL is searching for
files in, which can be changed by using IDL> cd, 'mydir' If you issue cd
and then ask for the environment variable again, it should be the same: only
the first item in IDL's internal path "." has changed. To get IDL's current
directory, try IDL> cd, CURRENT=curdir
Beannacht,
Sean O'Sea
In article <36409D18.FA925705@ssl.berkeley.edu>,
Harald Frey <hfrey@ssl.berkeley.edu> wrote:
> IDL> print,!version
> { sparc sunos unix 5.1 Apr 13 1998}
> IDL> pwd=getenv('PWD')
> IDL> print,pwd
> /disks/sprite/disk1/hfrey/idl/image/wic
> IDL> pwd=getenv('pwd')
> IDL> print,pwd
>
> IDL>
>
> With the name argument of getenv set to capital letters I get the right
> answer, but in small letters 'pwd' returns the null string. However, if
> I use the same command on the UNIX platform I get
>
> image1 [1] pwd
> /disks/sprite/disk1/hfrey/idl/image/wic
> image1 [2] PWD
> PWD: Command not found
>
> and UNIX does not like the capital letter 'PWD'.
>
> Any explanation?
>
> Harald Frey
> hfrey@ssl.berkeley.edu
>
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
|
|
|
Re: Strange UNIX or strange IDL? [message #13412 is a reply to message #13410] |
Wed, 04 November 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Harald Frey (hfrey@ssl.berkeley.edu) writes:
> IDL> print,!version
> { sparc sunos unix 5.1 Apr 13 1998}
> IDL> pwd=getenv('PWD')
> IDL> print,pwd
> /disks/sprite/disk1/hfrey/idl/image/wic
> IDL> pwd=getenv('pwd')
> IDL> print,pwd
>
> IDL>
>
> With the name argument of getenv set to capital letters I get the right
> answer, but in small letters 'pwd' returns the null string. However, if
> I use the same command on the UNIX platform I get
>
> image1 [1] pwd
> /disks/sprite/disk1/hfrey/idl/image/wic
> image1 [2] PWD
> PWD: Command not found
>
> and UNIX does not like the capital letter 'PWD'.
>
> Any explanation?
I think you are confusing the command ("pwd"), which in
UNIX (a case sensitive operating system) is always expressed
in lowercase characters, with the environment variable ("PWD")
which is always expressed in uppercase characters. (So
you can tell them apart. :-)
Here IDL is doing exactly the correct thing and getting
the Environment variable for you. When the environment
variable is undefined, you get a null string back.
If you are really just tying to get the current working
directory, here is an IDL program for you:
PRO PWD
CD, Current=thisDirectory
Print, thisDirectory
END
Wouldn't know how to get along without it. :-)
Cheers,
David
----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438, Toll-Free Book Orders: 1-888-461-0155
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Note: A copy of this article was e-mailed to the original poster.
|
|
|