in reply to command recall
hmm, how about something like:
The only major difference is that most everything is kept in perl which allows for more error checking (like dying if the file doesn't exist or can't open, which you could check anyway, but hey =).my $pattern = shift; #get the lines you're looking for in the file open HIST, "$HOME/.bash_history" or die "Couldn't open history file: $ +!\n"; my @list = grep { /$pattern/ and chomp and $_ } <HIST>; close HIST; #ask and run the commands foreach my $com (@list) { print "run [$com] (y/n)? "; my $ans = <STDIN>; $ans =~ /^y/i && do { my $result = `$com`; # error checking here print "result: $result\n"; }; }
There really isn't much difference between the two, but i think you typoed on the binding operator ($choice eq 'Y' is fine, but $choice =~ 'Y' doesn't make much sense).
HTH,
jynx
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: command recall
by Kickstart (Pilgrim) on Feb 13, 2001 at 04:13 UTC |