Thread View: comp.unix.shell
4 messages
4 total messages
Started by Frank B. Mostek
Thu, 18 Oct 1990 23:58
csh args
Author: Frank B. Mostek
Date: Thu, 18 Oct 1990 23:58
Date: Thu, 18 Oct 1990 23:58
6 lines
678 bytes
678 bytes
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
Re: csh args
Author: Paul John Falstad
Date: Fri, 19 Oct 1990 03:42
Date: Fri, 19 Oct 1990 03:42
24 lines
1542 bytes
1542 bytes
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.
Re: csh args
Author: Frank B. Mostek
Date: Fri, 19 Oct 1990 14:51
Date: Fri, 19 Oct 1990 14:51
38 lines
1935 bytes
1935 bytes
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 \;'
Re: csh args
Author: Paul John Falstad
Date: Fri, 19 Oct 1990 21:56
Date: Fri, 19 Oct 1990 21:56
53 lines
2668 bytes
2668 bytes
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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads