Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!uwvax!oddjob!gargoyle!ihnp4!ihuxy!lied From: lied@ihuxy.ATT.COM (Bob Lied) Newsgroups: comp.unix.questions Subject: Re: eval Message-ID: <2019@ihuxy.ATT.COM> Date: Sun, 5-Jul-87 19:02:40 EDT Article-I.D.: ihuxy.2019 Posted: Sun Jul 5 19:02:40 1987 Date-Received: Mon, 6-Jul-87 00:38:00 EDT References: <2771@ncoast.UUCP> Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 32 Summary: eval does a second pass In article <2771@ncoast.UUCP>, robertd@ncoast.UUCP (Rob DeMarco) writes: > > I have seen a lot of "eval" solutions. What I am wondering is exactly > what does "eval" do? eval performs a second pass over the command line, performing alias and variable substitution again. For example, suppose you set a="A" b='echo $a' then if you say $b the shell expands "$b" into "echo $a", but leaves "$a" literally, so you get $a On the other hand, if you say "eval $b", the shell does one parse that yields "eval echo $a", then the eval causes a second pass, which expands $a to "A", and the result is as if you had said "echo A". Summary: a=A b='echo $a' $b ( --> 'echo $a' ) $a eval $b ( --> eval 'echo $a' --> echo A ) A Several programming languages have an 'eval' feature; Lisp, APL and m4 to name a few. The feature is generally used by setting up a string that looks like a valid statement in the language, then executing the string as if it were part of the code. Bob Lied ihnp4!ihuxy!lied