programming a linux shell using the c programming language
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
programming a linux shell using the c programming language
hi every one. well straight to the point. am trying to build a simple linux shell(command line) using the c programming line and cygwin on windows machine. the shell will implement a few easy linux commands like ,cd, ls, pwd, using child processes and fork() function i guess- but i couldnt even make the cursor appear yet on my shell so far!
any help or form of assistance provided is greatly appreciated in advance. reply ASAP
thanks.
heey, i dont know who you are but i definitely know that you have gotten me going. Thanks a great deal!! now i guess i have no excuses!! let me get on with the fiddling and i will let you know as i proceed!
I think it is helpful to think of a shell as a way to expose kernel/system functionality to the end-user. Most of the things a typical shell does map directly, sometimes a bit indirectly, to core system functions, such as launching process, opening/reading/writing files & devices, setting process state like current working directory & the shell's environment, etc. On top of all of that is the built-in programming/scripting capability, which isn't completely necessary, but is a convenience.
I suggest that you use readline() from libreadline as the basis for your commandline processing.
--- rod.
well, i hear the shell wont then display a prompt when in this mode. it will just read the commands from a pre-written batch file and then simply display the commands and their out put. to activate or enter this mode i shoud type [batchfile] on the command prompt where "batchFile" is the name of the batch file prewritten.
Ok, that sounds more like reading and acting upon a shell file aka script file, which would make sense.
All a shell/script file really is, is a collection of cmds that you could run direct from the cli manually.
And to implement that, I would guess that you are expected to exercise some file-descriptor gymnastics, possibly involving pipe(), popen(), dup(), dup2(), and other functions that are probably referenced in the 'SEE ALSO' sections of the respective man pages.
thanks for the links and tips. the book links look good but they appear to need some time, so i will first take a look at the dup() function usage. 'coz i didnt expect this feature to take a lot of time. but i am planning on making a fully functioning shell so even if my project is done am sure to keep going.
by the way, for the record: you guys are alot of help really, this blog isn't just for show. you show lost sheep the way to light.
I LIKE THAT
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.