#!/usr/bin/perl # # The idea with this script is, you're cd'd to /u/jasper, # which doesn't have a db2 file in it, then invoke this # script via aixnotes/perl_examples/check_chdir.pl # print "\n1: Before doing anything, your current working directory\n"; print " according to \$ENV{\"PWD\"), is " , $ENV{"PWD"} , "\n"; print " according to \`echo \$PWD\`, is " , `echo \$PWD`; if (-r "db2") {print " I see a file named db2. (??) <------------\n"} else {print " I do not see a file named db2. (ok)\n"} # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # print "\n2: Now using Perl's chdir() function to cd to aixnotes ...\n"; chdir("aixnotes") or die "Ooops, couldn't chdir to aixnotes"; print " And now, your current working directory\n"; print " according to \$ENV{\"PWD\"), is " , $ENV{"PWD"} , ". Note it's not updated.\n"; print " according to \`echo \$PWD\`, is " , `echo \$PWD` ; if (-r "db2") {print " I see a file named db2. (ok)\n"} else {print " I do not see a file named db2. (??) <------------\n"} # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # print "\n3: Now using Perl's chdir() function to cd back to /u/jasper ...\n"; chdir('/u/jasper') or die "Ooops, couldn't chdir to /u/jasper"; print " And now, your current working directory\n"; print " according to \$ENV{\"PWD\"), is " , $ENV{"PWD"} , "\n"; print " according to \`echo \$PWD\`, is " , `echo \$PWD` ; if (-r "db2") {print " I see a file named db2. (??) <------------\n"} else {print " I do not see a file named db2. (ok)\n"} # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # print "\n4: Now using Perl's backtick `cd` function to cd to aixnotes ...\n"; `cd aixnotes`; print " And now, your current working directory\n"; print " according to \$ENV{\"PWD\"), is " , $ENV{"PWD"} , "\n"; print " according to \`echo \$PWD\`, is " , `echo \$PWD` ; if (-r "db2") {print " I see a file named db2. (??) <------------\n"} else {print " I do not see a file named db2. Expected 'cause a backtick'd cd is not long lasting.\n"} # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # print "\n5: Now using Perl's backtick `cd` function to cd back to /u/jasper ...\n"; `cd /u/jasper`; print " And now, your current working directory\n"; print " according to \$ENV{\"PWD\"), is " , $ENV{"PWD"} , "\n"; print " according to \`echo \$PWD\`, is " , `echo \$PWD` ; if (-r "db2") {print " I see a file named db2. (??) <------------\n"} else {print " I do not see a file named db2. (ok)\n"} # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #