Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-25-2005, 06:08 PM   #1 (permalink)
smckittr
Scott
 
Join Date: Aug 2005
Posts: 29
smckittr is on a distinguished road
big command line programs...

..such as ms dos command promt or unix, etc.
How do they figure out what to do with the command you gave them? for example if you type in exit how does it know to exit. Do they use a giant switch statement or some other method?
Just curious
Thanks
Scott
smckittr is offline   Reply With Quote
Old 08-25-2005, 06:41 PM   #2 (permalink)
Feis
Registered User
 
Join Date: Apr 2005
Posts: 18
Feis is on a distinguished road
Kinda. First off please feel free to correct me as Im sure I will make a mistake or two in the finer details. In each commandline (@ least Unix or windows) you have a PATH variable. It tells the commandline where to look if you just enter a command. so when u enter exit, it will search locations in the PATh variable (in Windows its system32) for the command, and then execute it. That why if u want to add a command or shell script so that u can run it from anywhere, u can either dump it in a folder such as system32, or you could add its location to the path variable itself. Hope that explains your ? without too many blatant errors
Feis is offline   Reply With Quote
Old 08-25-2005, 07:35 PM   #3 (permalink)
smckittr
Scott
 
Join Date: Aug 2005
Posts: 29
smckittr is on a distinguished road
makes sense to me,
thanks
Scott
smckittr is offline   Reply With Quote
Old 08-25-2005, 09:52 PM   #4 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
I'm pretty sure the way a shell's top loop looks is like this
Code:
//psuedo code
read_input_line();
tokenize();
if (expandable)  //for aliases and history substitutions
{
  rewrite_exapandable_tokens();
}

//Compare the first token to a list of built in commands
foreach ( builtin in builtin_list ) {
 if ( command_token == builtin )
 {
   execute->command_token( parameter_tokens );
   break;
 }
}

//If that didn't work try executing it as a filesystem command
try_execute_file_in_path( command_token );

//Finally just fail
signal_error();
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Are there any good Code highlight programs :S ? JeC PHP 19 05-09-2008 02:38 AM
Shared objects across different programs celerate Standard C, C++ 3 08-24-2005 04:06 AM
Big O notation saiz66 Standard C, C++ 1 06-22-2004 09:19 AM
Longhorn 'Big Bet' For Company redhead Code Newbie News 1 07-24-2003 04:11 PM
The Big 300! Ilya020 Lounge 7 03-02-2003 09:41 AM


All times are GMT -8. The time now is 11:24 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting