From: Janis Papanagnou on 21 Oct 2009 20:55 Danish wrote: > Hi, > > Although, I have worked on shell scripts and have some basic knowledge > about them, but while preparing a doc on shell scripting I got > confused by the definition: > > shell is an interpreter. An Interpreter is a computer program which > reads source code written in a high-level programming language, > transforms the code to machine code, and executes the machine code. An interpreter (for example the shell) reads the source code written in a higher-level programming language (for example shell script) and acts according to what the the interpreter has read. (Some interpreters have a more complicated/sophisticated mode of operation, though.) Those above mentioned "acts" may be either part of the shell itself, for example so called builtin commands, or shell control constructs, or shell specific syntactical constructs, or those "acts" may be calls of external commands; those external commands are typically compiled programs (or again scripts interpreted by some interpreter, which will be invoked by the shell). > But when I do a 'file' on 'who' (it says its an executable, and its > the same thing for other commands too) Programs like 'who' are those external precompiled commands. When a shell interpreter reads the shell script and comes to a point in the shell script code where it expects some form of a command, it checks for a couple forms of possible commands; e.g. (shown here in no particular order) for alias names of existing commands, for built-in commands, for shell defined function procedures of that name, and finally it searches for external commands at the places defined by the PATH definition. With builtins and aliases and function the shell has already all information necessary to interpret and exectute that code, for external programs the shell will make use of a Unix system call to invoke that program in the shell's context. > According to me it seems these unix-utilities ('who', etc) are > actually compiled programs and not just written in source code, but > then according to this the definition of an interpreter is wrong > because there is no transformation of the high level programming > language happening, rather i see it as a taking from the command and > giving it to the kernel to execute. The shell is just acting as a > traffic cop! > > help me clear these doubts please I think you've spotted the problem with the above definition very well. Hope my additional explanations were helpful as well. Janis > > Thanks > Danish
|
Pages: 1 Prev: get current timestamp in microseconds or milliseconds Next: Installed libraries |