C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-19-2006, 06:00 PM   #1
Registered User
 
Join Date: Nov 2005
Location: Canada
Posts: 80
basic shell command execution

In the code on the following page:
http://www.cs.cf.ac.uk/Dave/C/section2_22_22.html
a basic UNIX shell is represented. Why does commands such as rm, mv, mkdir, rmdir, ls, etc can be executed but many other ones such as cd, or & (background processing) have to be implemented in the code? i.e. the code doesn't define rm or mv but the system understands them when they're typed in this shell, but that's not the case with cd.

Please advise.
Opel_Corsa is offline   Reply With Quote
Old 10-19-2006, 08:09 PM   #2
Registered User
 
Join Date: Sep 2001
Posts: 752
execvp replaces the current process image with that of a different program.

rm, mv, mkdir, rmdir, ls, etc are all programs. You can find them in /usr/bin
cd and background processing are not programs, they are shell builtins.
__________________
Callou collei we'll code the way
Of prime numbers and pings!
QuestionC is offline   Reply With Quote
Old 10-19-2006, 09:35 PM   #3
Registered User
 
Join Date: Nov 2005
Location: Canada
Posts: 80
Thanks. So if execvp is replaced by execv, then this case will no longer be valid? i.e. those commands won't be recognized and need to be implemented inside the code?
Opel_Corsa is offline   Reply With Quote
Old 10-20-2006, 08:10 AM   #4
Registered User
 
Join Date: Sep 2001
Posts: 752
The difference between execv and execvp is just that execvp uses your $PATH variable for file lookup, and evecv does not.

So while you can do execvp("ls", NULL);
You have to do execv("\usr\bin\ls", NULL); to get the same effect.

None of the exec functions will perform cd unless you write a cd program (I think a script will work). If you want background processing, you have to implement it yourself.

Think of it this way.... this program you've posted is it's own shell. You can't expect it to use bash builtins any more than you would expect csh to use bash builtins.
__________________
Callou collei we'll code the way
Of prime numbers and pings!
QuestionC is offline   Reply With Quote
Old 10-20-2006, 08:37 AM   #5
Registered User
 
Join Date: Nov 2005
Location: Canada
Posts: 80
thanks. very useful.
Opel_Corsa is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script basic question PedroTuga Linux Programming 1 09-09-2006 03:24 AM
A basic shell question AngKar C# Programming 1 06-20-2006 05:18 PM
[ANN] New script engine (Basic sintax) MKTMK C++ Programming 1 11-01-2005 10:28 AM
Basic Shell Script-Very Frustrating kwigibo Linux Programming 8 05-19-2002 02:43 AM


All times are GMT -6. The time now is 04:31 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22