Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!usenet.ins.cwru.edu!cwns1!chet From: chet@cwns1.CWRU.EDU (Chet Ramey) Newsgroups: comp.unix.questions Subject: Re: which/type & built-ins : A question ? Message-ID: <1990Jan8.153921.14135@usenet.ins.cwru.edu> Date: 8 Jan 90 15:39:21 GMT References: <1297@quintus.UUCP> <1990Jan2.160927.11935@usenet.ins.cwru.edu> <8819.25a1ff8d@ecs.umass.edu> Reply-To: chet@po.CWRU.Edu Organization: Case Western Reserve Univ. Cleveland, Ohio, (USA) Lines: 45 I wrote: >> Because `while' is a sh language construct (a statement), not a shell >> builtin. and Kirtikumar Satam asks: >Can you elaborate more on this?? This is long and rambling (and not particularly clear), but I hope it catches the basic distinction between shell statements and builtins. The shell is, in effect, a complete interpreted programming language. In that language, there are statements provided as in any programming language, mostly looping and alternation constructs. Sh actually parses each complete statement in its input into a parse tree (sh uses a recursive descent parser, bash uses a yacc-generated parser), and executes it. While, if, for, until, and case statements are all sh language constructs. Shell builtins are parsed as any other command word would be; the fact that they are shell builtins is not discovered until the parse tree is executed. The C shell has everything as builtins, and uses ad-hoc parsing mechanisms to implement its `language constructs', with lots of special cases (which is why, for instance, it is so particular about the appearance of white space in its `if' statement). if [ -t 0 ] ; then echo terminal else echo no terminal fi is one sh statement that is parsed into a tree and executed. `if' is executed as a builtin by csh, and the if builtin is responsible for consuming as much input as it needs. This is one reason redirection in the C shell is so limited, like redirections into and out of loops. In sh, a statement is always completely parsed before it is executed, so redirections into and out of loops are trivial to implement. Chet Ramey -- Chet Ramey Network Services Group "Help! Help! I'm being Case Western Reserve University repressed!" chet@ins.CWRU.Edu