![]() |
| | #1 |
| Registered User Join Date: Nov 2005 Location: Canada
Posts: 80
| basic shell command execution 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 | |
| | #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 | |
| | #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 | |
| | #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 | |
| | #5 |
| Registered User Join Date: Nov 2005 Location: Canada
Posts: 80
| thanks. very useful. |
| Opel_Corsa is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |