[SOLVED] How to write a replacement for shell command line interpreter
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to write a replacement for shell command line interpreter
Hey,
If say, I want to read the input given by user at the command prompt and write a code to execute the cmd given then which commands do i use to implement this ( Im writing the code in C )?
Please give me a hint as to how do i start ?
Thanks
Ambika
Click here to see the post LQ members have rated as the most helpful post in this thread.
I'd use the readline library for taking the input, full line editing capabilities. As far as executing the command you'd probably want to do a fork and then exec (from the child process of the fork)
Hey,
If say, I want to read the input given by user at the command prompt and write a code to execute the cmd given then which commands do i use to implement this ( Im writing the code in C )?
Please give me a hint as to how do i start ?
In this particular case, google would be a good idea, not because I don't want to help you (I do), but because that is a very popular homework / project question in college, as a result of which, there are loads of comments/tips on this very qn on the internet by now.
I'd use the readline library for taking the input, full line editing capabilities. As far as executing the command you'd probably want to do a fork and then exec (from the child process of the fork)
'system' is simpler than 'fork', 'exec' to use and probably is sufficient in this case.
'system' is simpler than 'fork', 'exec' to use and probably is sufficient in this case.
It is simpler but why involve yet another shell when you are trying to replace one.
With fork/exec you have more control over how the parent deals with the child process, for example how it's stdin/stdout/stderr are attached, or what other file descriptors are left open for the child to access, or being able to send the child process signals.
I guess it just depends on what the OP wants to get out of this coding exercise.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.