Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax and semantic check

Status
Not open for further replies.

ravioli

Programmer
Mar 30, 2004
39
US
Does the shell perform a syntax and semantic check before commands are sent to the kernel?

Bradley
 
Syntax check for sure, semantic I'm not sure. I would say grammar check.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
[tt]$ echo )
bash: syntax error near unexpected token `)'[/tt]

That's a syntax error. The shell caught it.


[tt]$ cat --i-stink some-file
cat: unrecognized option `--i-stink'
Try `cat --help' for more information.[/tt]

That might be what you'd call a semantic error. The shell doesn't know what options [tt]cat[/tt] will accept, so it just passes them on. Then, when [tt]cat[/tt] sees those options and doesn't know what to do with them, it issues the error.


Now, the shell doesn't normally "send the commands to the kernel." If you run a command called [tt]cat[/tt], the shell just looks for an executable named "cat" in its PATH variable, then spawns a new process based on that executable.

If it's making a system call, like chdir (like from the [tt]cd[/tt] command, then the commands it uses are shell builtins, which means their code to evaluate arguments and perform their function is a part of the shell.

In that case, a part of the shell does do the semantic check, but only because it "is" the command, in a sense.
 
I think I am beginning to understand. Thank you Chipper and PHV!

Bradley
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top