| 1 | package Psh::Builtins::Forfile; | ||
| 2 | |||
| 3 | =item * C<forfile globpattern command> | ||
| 4 | |||
| 5 | Comparable to the sh-for command: | ||
| 6 | |||
| 7 | for i in globpattern; do command $i; done | ||
| 8 | |||
| 9 | The current filename will be assigned to $_ | ||
| 10 | |||
| 11 | Examples: | ||
| 12 | |||
| 13 | forfile *.zip unzip $_ | ||
| 14 | |||
| 15 | =cut | ||
| 16 | |||
| 17 | require Psh::Parser; | ||
| 18 | require Psh; | ||
| 19 | require Psh::Util; | ||
| 20 | |||
| 21 | sub bi_forfile { | ||
| 22 | my @words=@{$_[1]}; | ||
| 23 | my @files= Psh::OS::glob(Psh::Parser::unquote($words[0])); | ||
| 24 | foreach my $file (@files) { | ||
| 25 | $command= join(' ',@words[1..$#words]); | ||
| 26 | Psh::evl("\$\_=\"$file\"; $command"); | ||
| 27 | } | ||
| 28 | return (1,undef); | ||
| 29 | } | ||
| 30 | |||
| 31 | 1; |