Need csh alias to match patterns in history
Maarten Litmaath
maart at cs.vu.nl
Thu Mar 30 15:38:28 AEST 1989
naim at eecs.nwu.edu (Naim Abdullah) writes:
\A friend of mine wants a csh alias that will print all lines in
\the history list that match a pattern if one is supplied, otherwise
\just print the history.
\He asked me and I suggested the following csh alias:
\alias h ' \
\if ( "X\!*" == "X" ) then \
\history \
\else \
\history | grep \!* \
\endif'
\For some reason, this does not work.
Welcome to csh! Generally it doesn't like foreach, while, etc. in aliases.
Solutions:
alias h 'set q=(\!*); eval h$#q'
alias h0 history
alias h1 '(history | sed -n -e \$q -e /"$q"/p)'
or
alias h 'if ("\!*" == "") set status=1 &&'\
'history | sed -n -e \$q -e /"\!*"/p ||'\
history
or
alias h 'if (\!* == "") set status=1 &&'\
'history | sed -n -e \$q -e /\!*/p ||'\
history
The final version causes csh to complain if multiple arguments are given.
BTW, it's obvious why I used sed instead of grep.
--
Modeless editors and strong typing: |Maarten Litmaath @ VU Amsterdam:
both for people with weak memories. |maart at cs.vu.nl, mcvax!botter!maart
More information about the Comp.unix.questions
mailing list