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.
i want to write my own shell(micro),which has limited feautures.suppose the command copy old new to work,wat i need to do.i can write the program to perform the operation of copy,but how can i create executable for copy??
Copy (cp) is a separate program, and not part of the shell. You must learn the basics of programming before you can start replacing parts of the system.
Shell is a program, but most (or many) of the "commands" you run are executables of their own. You'll see it easily by issuing
Code:
which commandname
in your shell, to see where commandname is - if it shows it's in some bin/ directory (or any other for that matter), it's a separate executable. Shells have some builtin "functions", like TAB-completion, if-else statements etc. but they depend on the shell. For example DOS doesn't have copy built-int; it's a separate executable in a system directory where DOS can find it.
If you want to write a shell, I suggest you start learning basics of programming, maybe best done (in this case) with C. Then you need a compiler to compile the code into an executable. Writing a very minimalist shell is not that difficult, but it's another matter to make one that is of use.
The shell is not nearly as magical as it seems at first. A rudimentary shell can be written in a few lines of code. In it's most basic form, it is a loop that reads its standard input, and invokes other programs using fork() + exec() + wait(). It may understand a set of it's own commands which it performs using internal code. Most of the functionality is already present in the standard C library. There are numerous examples of simple shells in textbooks and on the net. Depending on where in the spectrum of simplicity - complexity you want your shell to be, there is probably an open source version which will either work straight away, or can be easily modified to include the functions you want.
--- rod.
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197
Rep:
Another aspect of "what is a shell" is how it gets used. Some vendor supplied turnkey systems have user shells which are menus for that system -- for example, a library catalog system (before web interfaces took over). In this case, if you look at /etc/passwd, you would see that the shell assigned for user accounts is, maybe, something like /usr/local/bin/iiish. A user who logs into that system is locked in to the menu for the catalog.
Such shells can be relatively simple shell scripts themselves (e.g., #!/bin/ksh) which start out by trapping interrupts to prevent people from breaking out of them. The O'Reilly book on learning the korn shell has some examples. So, you don't have to get into C. You could really do it in almost anything, depending on what your requirements are.
Unix shell accounts on such a system would be rare and for sysadmins only.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.