Next System Programming in Perl 14

World's Smallest Shell That Doesn't Completely Suck

(continued)

        sub parse {
          my @words = grep $_ =~ /\S/, split /( \s+ | < | >> | > )/x, $_[0];
          my %d;
          $d{program} = shift @words;
          while (@words) {
            local $_ = shift @words;
            if ($_ eq '<') {
              $d{stdin} = shift @words;
            } elsif ($_ eq '>' || $_ eq '>>') {
              $d{stdout} = shift @words;
              $d{append} = $_;
            } else {
              push @{$d{args}}, $_;
            }
          }
          %d;
        }


Next Copyright © 2003 M. J. Dominus