Macro facility in csh?

Maarten Litmaath maart at cs.vu.nl
Sat Sep 2 07:28:58 AEST 1989


charleen at zodiac.ADS.COM (Charleen Bunjiovianna) writes:
\I may be asking for too much, but I write a lot of csh scripts and
\it sure would be handy to have macro capability.  I don't find any
\mention of it in the documentation, though.

There always has been a macro facility (!):

	set	foo = bar
	... $foo ... $foo ... $foo ...

Allright, you want macros with PARAMETERS: well, why don't you filter your
script through `/lib/cpp -P' before passing it to the shell?

If you would use *Bourne* shell scripts, you could even define shell FUNCTIONS:

	foo()
	{
		...
	}
	... foo ...

If you're stuck with an old version of the Bourne shell, try the following
trick:
	foo='
		case $1 in
		bar)
			date
			;;
		pipo)
			who
		esac
	'
	...
	set bar; eval "$foo"
	set pipo; eval "$foo"

In fact, this is the way functions were implemented at first: the shell would
set the arguments you gave and eval the function shell variable.
The problem: the (global) positional parameters get overwritten on each call,
making nested functions somewhat `tricky'...
-- 
C, the programming language that's the same |Maarten Litmaath @ VU Amsterdam:
         in all reference frames.           |maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.unix.questions mailing list