Thread View: comp.unix.shell
5 messages
5 total messages
Started by Suntioinen Ari
Tue, 23 Oct 1990 04:36
Multiline aliases in csh ?
Author: Suntioinen Ari
Date: Tue, 23 Oct 1990 04:36
Date: Tue, 23 Oct 1990 04:36
14 lines
887 bytes
887 bytes
Is there any way to define multi line alias in csh ? What I mean is (for example) if-else or foreach loop as a part of alias. I tried it some time and just couldn't make it work. PS. Right answer is not "use scripts". PPS. Would be nice to have functions in csh. -- Ari Suntioinen "Scitsophrenia is the cure for cancer.. Opiskelijankatu 4C162 Cancer is probably the cure for scitsophrenia.. 33720 Tampere, Finland People just don't know how tough it is out there."
Re: Multiline aliases in csh ?
Author: Jonathan I. Kamens
Date: Tue, 23 Oct 1990 05:03
Date: Tue, 23 Oct 1990 05:03
29 lines
1405 bytes
1405 bytes
In article <APS.90Oct23053623@kaarne.tut.fi>, aps@tut.fi (Suntioinen Ari) writes:
|> Is there any way to define multi line alias in csh ?
|> What I mean is (for example) if-else or foreach loop
|> as a part of alias. I tried it some time and just
|> couldn't make it work.
In a word, no.
There are ways to get around it for if-else, for example checking the
condition for every statement in the if. If you have this in a shell script:
if (foo) then
bar
baz
else
frelt
endif
Then you can have an alias that does this:
if (foo) bar; if (foo) baz; if (! foo) frelt
I don't think there's any way to get around it for foreach.
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik@Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8085 Home: 617-782-0710
Re: Multiline aliases in csh ?
Author: Larry Wall
Date: Tue, 23 Oct 1990 18:58
Date: Tue, 23 Oct 1990 18:58
26 lines
1332 bytes
1332 bytes
In article <APS.90Oct23053623@kaarne.tut.fi> aps@tut.fi (Suntioinen Ari) writes: : Is there any way to define multi line alias in csh ? : What I mean is (for example) if-else or foreach loop : as a part of alias. I tried it some time and just : couldn't make it work. No, but you can often get the same effect using a program that forces multiple commands back into your input: alias patchit forceme "'"'foreach file (*.pat)'"'"\; \ forceme "'"'patch <$file'"'"\; \ forceme 'end' Won't work in a script, of course, but if you're just interested in being a lazy typist... : PS. Right answer is not "use scripts". Why not? Assuming a reasonable script language, of course... :-) : PPS. Would be nice to have functions in csh. Some would call this "throwing good money after bad". Larry Wall lwall@jpl-devvax.jpl.nasa.gov
Re: Multiline aliases in csh ?
Author: Dan Bernstein
Date: Tue, 23 Oct 1990 21:22
Date: Tue, 23 Oct 1990 21:22
56 lines
1814 bytes
1814 bytes
In article <10084@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
> No, but you can often get the same effect using a program that forces
> multiple commands back into your input:
> alias patchit forceme "'"'foreach file (*.pat)'"'"\; \
> forceme "'"'patch <$file'"'"\; \
> forceme 'end'
I assume that ``forceme'' uses TIOCSTI to simulate terminal input. For
readers without it, enclosed is tiocsti, which does the same job.
> Won't work in a script, of course, but if you're just interested in being
> a lazy typist...
Right. Btw, why don't you use \' rather than "'"? Might not work in
awk, of course, but if you're just interested in being a lazy typist...
Actually, it'd be a lot clearer to just double-quote your entire alias.
---Dan
/* Public domain. */
#include <sys/ioctl.h>
main(argc,argv)
int argc;
char *argv[];
{
int j;
char *s;
if (ioctl(3,TIOCGPGRP,(char *) &j) == -1)
(void) dup2(0,3);
for (j = 1;j < argc;j++)
{
for (s = argv[j];*s;s++)
(void) ioctl(3,TIOCSTI,s);
if (j < argc - 1)
(void) ioctl(3,TIOCSTI," ");
}
}
TH tiocsti 1
SH NAME
tiocsti \- simulate terminal input
SH SYNOPSIS
B tiocsti
[
I arg
] ...
SH DESCRIPTION
I tiocsti
``types'' each of its arguments on the
current terminal, separated by spaces,
as if you had typed them.
SH "SEE ALSO"
tty(4)
Re: Multiline aliases in csh ?
Author: Joe Wells
Date: Thu, 25 Oct 1990 08:58
Date: Thu, 25 Oct 1990 08:58
34 lines
1482 bytes
1482 bytes
aps@tut.fi (Suntioinen Ari) writes:
Is there any way to define multi line alias in csh ?
What I mean is (for example) if-else or foreach loop
as a part of alias.
Sure, here's an appropriately twisted example:
alias which '(set argv=($path) target=\!*; whichi)'
alias whichi 'if (! $#argv) set status=1 && whichii'
alias whichii \
'if (-x "$1/$target") set status=1 && shift && eval "whichi" \\
|| if ($#argv > 0) echo "$1/$target"'
Conditionals are done with:
if (condition) set status=1 && else-statement || then-statement
Looping is done with recursion, which requires you to use "eval",
otherwise the csh will detect the recursion and refuse to do it.
Note, the last line should actually read:
|| echo "$1/$target"'
but yet another csh bug prevents it from working that way.
Enjoy,
--
Joe Wells <jbw@bu.edu>
PS. I think this example clearly justifies why the author(s) of the csh
will be roasting in hell for a long long long time.
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