Macro facility in csh?
Jonas Mellin
jonas at his.UUCP
Mon Sep 4 16:09:54 AEST 1989
In article <8998 at zodiac.ADS.COM> charleen at ADS.COM () 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.
>
>Responses on the order of "Well, shoot, if you want that much
>flexibility you should be using ______" welcome as well.
>
>Charleen
It is possible to use aliases for the purpose.
alias cd 'set old=$cwd; chdir \!*; pwd'
alias back 'set back=$old; cd $back; unset back'
Here is an example using it:
...> cd /tmp
/tmp
...> back
(whereever you were before)
...>
or
set pdl=
alias pd 'chdir \!:1;set pdl=($pdl $cwd); pwd'
alias ccd 'echo $pdl; echo -n index: ; set pdi=$<; chdir $pdl[$pdi]; pwd'
alias cdn 'chdir $pdl[\!:1]; pwd'
alias ud 'echo $pdl; echo -n index:; set pdi=$<; @ pdii=$pdi + 1;'\
'@ pdi=$pdi - 1; set pdl=($pdl[-$pdi] $pdl[$pdii-]);'\
'echo $pdl; unset pdi pdii'
alias pdreset set pdl=
where
pd registers a directory in the pdl
ccd displays pdl first and prompts the user for an index. If an
correct index is used it changes to the directory
cdn change to the nth directory in the indexlist.
ud removes a directory from pdl
pdreset resets pdl to an empty list
Both of these examples are from the book 'An Introduction To Berkeley UNIX'.
I am more inclined to use Bourne Shell for shellscript programming.
_____________________________________________
/ / / / /\ / / /| /| |E-mail: jonas at his.se
/ /--/ / \ / / / |/ | |UUCP: ...!sunic!his!jonas
/ / / / \/ / / / / | |Phone: +46 500 77646
/______________________/ \_/ onas / |ellin|Fax: +46 500 16325
Snailmail: Jonas Mellin,Hogskolan i Skovde, Box 408, 541 28 Skovde, Sweden
More information about the Comp.unix.questions
mailing list