• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

I'AM PLANNING TO WRITE A SIMPLE SHELL PROGRAM FOR LINUX HOW SHOULD I START?

I'AM PLANNING TO WRITE A SIMPLE SHELL PROGRAM FOR LINUX HOW SHOULD I START?
0
ALNMOO
Asked:
ALNMOO
1 Solution
 
leflonCommented:
hi alnmoo,

could you explain a little bit more of what you like to do?
what shall the prog do? etc.

leflon
0
 
sunnycoderCommented:
Duplicate question.

Experts please post here
http:Q_20952053.html
0
 
ALNMOOAuthor Commented:
this is my question

Write a special simple command interpreter that takes command(s) and its(their) arguments. This special command interpreter will only have three different cases that need to be addresses in your interpreter program.

1.      If it is a single command, the main process creates a child process to execute the command using exec() family functions. After executing the command, it asks for new command input. (parent wait for child)

2.      If it is a single command and it is to be executed in background, (that is, the command line has a & symbol at end) the interpreter wont wait for its child.

3.      If the command is a multiple background command, (eg. cd lab5 &; ls &) [that is if the background commands are separated by the symbol ; ] then the interpreter creates a number of child processes, equal to the number of commands and executes one after the other in the same order as appear in the command line. Each child process will execute one command using exec family of functions. (parent will not wait for any child. Make sure the first command child process finishes first and then the second starts)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sunnycoderCommented:
Membership agreement forbids posting and answering homework questions. Experts here cannot do your homework

http://www.experts-exchange.com/memberAgreement.jsp

Make some efforts on your own and if you are stuck somewhere ask here and we shall be glad to help you out.

sunnycoder
0
 
ray_pro2Commented:
Dear ALNMOO,

First of all you must understand when to use a shell script and when not to. In general, you use a shell script when:

     1. Customizing your work environment
     2. Automating your daily tasks.
     3. Automating repetitive tasks.
     4. Performing same operations on many files.

A shell script is not executed under the current shell. Instead a new shell is created to execute the script. Thus there is a limit to which a shell script can remain efficient even on being complex. This tells you, that you SHOULD NOT write/use a shell script when:

     1. It is too complex (like your proposed command interpreter).
     2. Requires a high degree of efficiency.
     3. Requires resources that are too many and too costly.

The morale of the story is stop thinking of writting a shell script for creating your special command interpreter - as it is too complex. Write a C proigram insted - which is both easy to write as well gurantee greater efficiency. Availablity of fork() and exec()/exev() functions can make the job much more easy.

If writting a shell program/script is all you are after then there is a simple advice for you : The philosophy of shell scripting/programming is very straightforward. A linux shell executes commands that you type into a terminal. Internally, linux like any other UNIX system treats your terminal as a file, in which the commands are present in the form of character strings. The speciality of the linux (or any UNIX) shell is that, it can not only execute commands from the terminal file, but also from any other file. This is conceptually very similar to the batch file of MS-DOS. But a shell script/program can do much more than just executing commands in a batch. It can also provide programming constructs like if, if-then-else, case-construce, for loop, while loop, until loop, functions and much more.

So just sum up all the commands together that you need to bundle together to perform your task, put them in a text file ( one command in each line), and save it. This is your shell script. Give it execution permissions (use chmod +x filename). And run it -- Thats it.

Hope you make your mind.
                                                 -------------------------------ray_pro2

0
 
Computer101Commented:
PAQed, with points refunded (500)

Computer101
E-E Admin
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now