Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!unmvax!pprg.unm.edu!hc!lll-winken!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re: Need csh alias to match patterns in history Keywords: sed, sed, sed, csh, Bill 'bug' Joy, Bugs Bunny Message-ID: <2227@solo11.cs.vu.nl> Date: 30 Mar 89 05:38:28 GMT References: <3680046@eecs.nwu.edu> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 36 naim@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@cs.vu.nl, mcvax!botter!maart