LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-21-2007, 12:14 AM   #1
anoop ss
LQ Newbie
 
Registered: Sep 2005
Location: bangalore
Posts: 9

Rep: Reputation: 0
how to create my own shell


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??
 
Old 08-21-2007, 12:21 AM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
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.
 
Old 08-21-2007, 01:03 AM   #3
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
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.
 
Old 08-21-2007, 06:27 AM   #4
anoop ss
LQ Newbie
 
Registered: Sep 2005
Location: bangalore
Posts: 9

Original Poster
Rep: Reputation: 0
i thank you very much for your suggestions....
 
Old 08-21-2007, 12:37 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 08-21-2007, 07:45 PM   #6
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how can create shell script user52 Linux - Newbie 4 11-27-2006 11:16 AM
how create shell script user52 Linux - General 1 11-27-2006 03:35 AM
create a unix shell rahulpnath Programming 19 05-26-2006 10:24 AM
hey guys help me to create my shell! sri_hassan Ubuntu 3 10-10-2005 01:23 PM
Create Shell Shortcut for Terminal PhuckFonix Linux - Newbie 6 03-29-2004 07:36 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration