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

Shell facility

The following awk program simulates (crudely) the history facility of the C shell:

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

$1 != "=" { system(x[NR] = $0) }

A line containing only = re-executes the last command executed. A line beginning with =<space>cmd re-executes the last command whose invocation included the string cmd. Otherwise, the current line is executed.
Previous topic: Random choice

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005