Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site osu-eddie.UUCP Path: utzoo!watmath!clyde!cbosgd!osu-eddie!karl From: karl@osu-eddie.UUCP (Karl Kleinpaste) Newsgroups: net.unix-wizards Subject: Re: Help! Csh is eating my brain.... Message-ID: <661@osu-eddie.UUCP> Date: Fri, 18-Oct-85 09:35:18 EDT Article-I.D.: osu-eddi.661 Posted: Fri Oct 18 09:35:18 1985 Date-Received: Sat, 19-Oct-85 04:11:28 EDT References: <367@zaphod.UUCP> Organization: OSU Lines: 36 > I'm trying to debug a csh script... > ... > 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. In csh, the alias command sets the aliased name to the value of the other words in the line. In this example, that's one long quoted word, but that's OK. Within the alias command, one can use standard csh history expansions to parse the arguments to be given to the alias itself. That is, the alias, once expanded, is considered momentarily to be the previous com- mand, which makes it available for history expansion. In history references, the ! sequences introduce pieces of that event. Specifically, anything of the form : refers to the th argument of the command specified by the . The usage of ! by itself refers to the immediately preceding event, i.e., the aliased command itself. Thus, in the call readandset "Choice?" chvar the string "Choice?" is the 1st argument, and chvar is the 2nd. Hence, when the entire command using the readandset alias is used, it creates the following command line: echo -n "Choice?" ; set chvar = $< which lets the user input a choice as variable chvar. The reason that the ! was escaped as \! in the alias command itself was to keep the alias command itself from referring to history events; it introduced the literal character ! into the alias declaration, so that it would be available during alias expansion to parse arguments. -- Karl Kleinpaste