mostek@motcid.UUCP (Frank B. Mostek) (10/19/90)
How does one pass several args (more than 2), other than the !^, !*, !$ mechanisms, to aliases in csh? I have read the man page, read the UNIX C Shell Field Guide, and "played around" for about an hour. Frank Mostek - (708)632-7191 uunet!...motcid!marble!mostek
pfalstad@phoenix.Princeton.EDU (Paul John Falstad) (10/19/90)
In article <4861@crystal1.UUCP> mostek@motcid.UUCP (Frank B. Mostek) writes: >How does one pass several args (more than 2), other than the !^, !*, !$ >mechanisms, to aliases in csh? I have read the man page, read the UNIX >C Shell Field Guide, and "played around" for about an hour. I'm not exactly sure what you want to do. Do you know about the !:n syntax? % alias first echo \!:1 % alias second echo \!:2 % alias swap echo \!:2 \!:1 % second a b c b If you have something specific you want, it's probably possible. The only way to pass arguments is through this pseudo-history-mechanism thing (unless you want all the arguments intact, of course). Very kludgy. It's too bad csh doesn't have shell functions. -- Paul Falstad, pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD And Dinsdale said, "You've been a naughty boy, Clement," and splits me nostrils open, and saws me leg off, and pulls me liver out. And I said, "My name's not Clement." And then he loses his temper. And he nails me head to the floor.
mostek@motcid.UUCP (Frank B. Mostek) (10/19/90)
pfalstad@phoenix.Princeton.EDU (Paul John Falstad) writes: >In article <4861@crystal1.UUCP> mostek@motcid.UUCP (Frank B. Mostek) writes: >>How does one pass several args (more than 2), other than the !^, !*, !$ >>mechanisms, to aliases in csh? I have read the man page, read the UNIX >>C Shell Field Guide, and "played around" for about an hour. >I'm not exactly sure what you want to do. Do you know about the !:n syntax? >% alias first echo \!:1 >% alias second echo \!:2 >% alias swap echo \!:2 \!:1 >% second a b c >b >If you have something specific you want, it's probably possible. >The only way to pass arguments is through this pseudo-history-mechanism >thing (unless you want all the arguments intact, of course). Very >kludgy. It's too bad csh doesn't have shell functions. >-- >Paul Falstad, pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD >And Dinsdale said, "You've been a naughty boy, Clement," and splits me nostrils >open, and saws me leg off, and pulls me liver out. And I said, "My name's not >Clement." And then he loses his temper. And he nails me head to the floor. One example is a search alias : alias sea 'find \!:1 -name "\!:2" -print -exec grep \!:3 {} \;' Other things I would like to do would be to only "print" the files that grep finds a pattern in, and pipe the grep into more. The following alias does not work: alias sea 'find \!:1 -name "\!:2" -print -exec grep \!:3 {} | more \;'
pfalstad@fish.Princeton.EDU (Paul John Falstad) (10/20/90)
In article <4864@crystal1.UUCP> mostek@motcid.UUCP (Frank B. Mostek) writes: >One example is a search alias : >alias sea 'find \!:1 -name "\!:2" -print -exec grep \!:3 {} \;' Right, this works. For example, "sea . *.c main". >Other things I would like to do would be to only "print" the files that grep >finds a pattern in, and pipe the grep into more. > >The following alias does not work: > >alias sea 'find \!:1 -name "\!:2" -print -exec grep \!:3 {} | more \;' No it doesn't, for several reasons. First of all, you forgot to escape the |. The shell was interpreting that whenever you executed the alias. I assume you wanted the | passed to find, because you put a \; after it. Second of all, even if you did escape the |, this wouldn't work because find does not accept shell metacharacters. It would just stupidly pass the | and more to grep as filenames. Also, I'm not sure this does what you want. It runs more once for each file it finds a string in (rather inefficient) and it prints the names of all files that match the pattern, not just the ones that have the string in them. Try: alias sea 'find \!:1 -name "\!:2" -exec grep \!:3 {} \; -print | more' Although that prints the lines matched and THEN the file, if that's acceptable. Or you could try: alias sea 'find \!:1 -name "\!:2" -print | xargs grep \!:3 | more' I suggest removing the double quotes around \!:2; they're rather confusing. Something like "sea . *.c main" implies that you want the shell to expand the *, which is not what happens. You probably can't get EXACTLY what you want without writing either a shell script or a ridiculously large alias. #! /bin/sh for i in `find "$1" -name "$2" -print | xargs grep -l "$3"` do echo $i grep "$3" $i done | more -- Paul Falstad, pfalstad@phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD And Dinsdale said, "You've been a naughty boy, Clement," and splits me nostrils open, and saws me leg off, and pulls me liver out. And I said, "My name's not Clement." And then he loses his temper. And he nails me head to the floor.
gt0178a@prism.gatech.EDU (Jim Burns) (10/20/90)
in article <4864@crystal1.UUCP>, mostek@motcid.UUCP (Frank B. Mostek) says: > Other things I would like to do would be to only "print" the files that grep > finds a pattern in, and pipe the grep into more. > The following alias does not work: > alias sea 'find \!:1 -name "\!:2" -print -exec grep \!:3 {} | more \;' Move the '\;' to the other side of the '|': alias sea 'find \!:1 -name "\!:2" -print -exec grep \!:3 {} \; | more ' This, however, only works for explicit filenames. To use (quoted) wildcard characters, add an 'eval' and some extra '\'s: alias sea 'eval find \!:1 -name \"\!:2\" -print -exec grep \!:3 {} \\\; | more' Then 'sea subdir \* pat' will work. The '-print' causes *every* filename to be printed out. Without it, you can only get the filenames for matching files printed out with 'xargs' or a for loop, ala P.J.Falstad's suggestions. -- BURNS,JIM Georgia Institute of Technology, Box 30178, Atlanta Georgia, 30332 uucp: ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt0178a Internet: gt0178a@prism.gatech.edu