| Next | System Programming in Perl | 25 |
In fact, the cd 'command' is not a command at all
There is no /bin/cd
cd must always be implemented as a shell built-in command
%builtin = (cd => sub { chdir $_[0]
|| warn "Couldn't chdir to $_[0]: $!\n"; },
);
while (1) {
print "perl% ";
my $command = <STDIN>;
last if $command eq '';
chomp $command;
my (%command) = parse($command);
if (defined my $builtin = $builtin{$command{program}}) {
$builtin->(@{$command{args}});
next;
}
...
}
| Next | ![]() |
25 |