#!/usr/bin/perl use strict; my $program = $ARGV[0]; if ($program eq "-h") { print "usage: choose program choice program\n"; print "example: choose vim find /etc -iname httpd.conf"; exit(1); } my $choice = $ARGV[1]; my $i; for ($i=2;$i<=$#ARGV;$i++) { $choice .= " ".$ARGV[$i]; } my @choices = split(/\n/,`$choice 2>/dev/null`); if ($#choices < 0) { print "No results.\n"; exit(1); } elsif ($#choices == 0) { system("$program ".$choices[0]); } else { for ($i=0;$i<=$#choices;$i++) { my $j = $i+1; print "$j) ".$choices[$i]."\n"; } print "use which option? "; my $input = ; if ($input<=$#choices && $input>0 && $input == m/[0-9]*/) { system("$program ".$choices[$input-1]); } print "No such option.\n"; exit(1); }