Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site luke.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!oliveb!bene!luke!itkin From: itkin@luke.UUCP (Steven List) Newsgroups: net.unix Subject: Re: Help! Csh is eating my brain.... Message-ID: <344@luke.UUCP> Date: Sun, 20-Oct-85 14:04:37 EDT Article-I.D.: luke.344 Posted: Sun Oct 20 14:04:37 1985 Date-Received: Tue, 22-Oct-85 05:18:50 EDT References: <366@zaphod.UUCP> Reply-To: itkin@luke.UUCP (Steven List) Organization: Benetics Corp, Mt.View, CA Lines: 44 Summary: In article <366@zaphod.UUCP> you write: > alias readandset 'echo -n \!:1 ; set \!:2 = $< ' > ... > readandset "Choice? " chvar > ... > if("$chvar" == "quit") .... > > In particular I'd like to know what \!:1 or \!:2 means/does. Aliases use current line history replacement. \!:n means "replace with word n of the current command line", where 0 is the first word (usually the command itself). If readandset were to be written as a Bourne shell script, it would be as follows: prompt=$1 echo "$1\c" < /dev/tty > /dev/tty read X echo X and used as chvar=`readandset "Choice? "` thus storing the user's input into variable chvar. The use of "$<" in the alias is the equivalent of "read chvar" in Bourne shell or the alternate "set chvar = `line`" in C shell (ours does not support $<). Thus, readandset can be define is pseudocode as print the second word of this command as a prompt without a following newline store the response typed in in the variable named as the second argument (word 2, third object) The use of \!:n, where n can be any number, * (for all), or $ (for last), is a very powerful means of defining macros in the C shell. I use them all over the place very effectively (also refer to various means of implementing popd, pushd directory change macros). -- *** * Steven List @ Benetics Corporation, Mt. View, CA * Just part of the stock at "Uncle Bene's Farm" * {cdp,greipa,idi,oliveb,plx,sun,tolerant}!bene!luke!itkin ***