in reply to command recall


Update: this node has been changed from it's original post, it has been posted to try to answer the question

hmm, how about something like:

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"; }; }
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 =).

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
    >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).

    Nah, I did that to avoid people being silly and typing 'Yes' or 'yes' instead. This way, if the inputted string contains Y or y it will still catch it. Unless the user (me) is silly enough to type 'Ny' or something.

    Greg