Solved

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

Posted on 2004-04-13
9
286 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
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 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