Thursday, 12 September 2013

How Perl can execute a command in the same shell with it?

How Perl can execute a command in the same shell with it?

I am not sure whether the title is really make sense to this problem. My
problem is simple, I want to write a perl script to change my current
directory and hope the result can be kept after calling the perl script.
The script looks like this:
if ($#ARGV != 0) {
print "usage: mycd <dir symbol>";
exit -1;
}
my $dn = shift @ARGV;
if ($dn eq "kite") {
my $cl = `cd ./private`;
print $cl."\n";
}
else {
print "unknown directory symbol";
exit -1;
}
However, my current directory doesn't change after calling the script.
What is the reason? How can I resolve it?

No comments:

Post a Comment