DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with awk

History facility

The following awk program roughly simulates the history facility of certain shells. A line containing only = re-executes the last command executed. A line beginning with = cmd re-executes the last command whose invocation included the string cmd. Otherwise, the current line is executed.

   $1 == "=" { if (NF == 1)
                   system(x[NR] = x[NR-1])
               else
                   for (i = NR-1; i > 0; i--)
                           if (x[i] ~ $2) {
                                   system(x[NR] = x[i])
                                   break
                           }
               next }
   

/./ { system(x[NR] = $0) }


Next topic: Form-letter generation
Previous topic: Random choice

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004