Solved

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

Posted on 2004-04-13
9
290 Views
Last Modified: 2010-04-22
I'AM PLANNING TO WRITE A SIMPLE SHELL PROGRAM FOR LINUX HOW SHOULD I START?
0
Comment
Question by:ALNMOO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 7

Expert Comment

by:leflon
ID: 10811736
hi alnmoo,

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

leflon
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10811743
Duplicate question.

Experts please post here
http:Q_20952053.html
0
 
LVL 7

Author Comment

by:ALNMOO
ID: 10811800
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
Industry Leaders: 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!

 
LVL 45

Expert Comment

by:sunnycoder
ID: 10811829
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
 

Expert Comment

by:ray_pro2
ID: 10882549
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12185419
PAQed, with points refunded (500)

Computer101
E-E Admin
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question