[X-Unix] How to get working directory in a perl script?
Jerry Krinock
jerry at ieee.org
Sun Apr 6 14:49:50 PDT 2008
Apparently, a perl script has a different "working" directory than the
bash shell that spawned it, or something like that...
##### Script: ##########################
#!/usr/bin/perl
print "1. pwd is: $ENV{'PWD'}\n" ;
my $newDir = "/Users/jk/Music" ;
if (chdir $newDir) {
print "Succeeded chdir to $newDir\n" ;
}
my $wdContents = `ls` ;
print "wd contents:\n$wdContents\n" ;
print "2. pwd is: $ENV{'PWD'}\n" ;
##### Actual Output: ##################
1. pwd is: /Users/jk
Succeeded chdir to /Users/jk/Music
wd contents:
GarageBand
iTunes
2. pwd is: /Users/jk
######################################
As you can see, the script did successfully change my working
directory to /Users/jk/Music, but $ENV{'PWD'} is giving me /Users/jk.
How can I get the correct answer?
Thanks,
Jerry Krinock
More information about the X-Unix
mailing list