?
Solved

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

Posted on 2004-04-13
9
Medium Priority
?
291 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

770 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