QUESTION...simple program?


 
Thread Tools Search this Thread
Top Forums Programming QUESTION...simple program?
# 1  
Old 02-02-2002
Question QUESTION...simple program?

I am new to the unix/linux environment.
AND........
I need to create a mini shell..that displays prompt (i.e., READY:$), accepts a command from std-in, and prints the command and any parameters passed to it. HELP!!!!
# 2  
Old 02-03-2002
I think you can try the simple code:

----------------------------------------------------------------------------
#!/usr/bin/ksh

agreed=
while [ x$agreed = x ]; do
printf "Ready:$>"
read receive
ksh -c "$receive"
echo
echo "Do you want to continue? [yes or no] "
read reply leftover
case $reply in
y* | Y*)
agreed=;;
n* | N*)
echo "*** Shell Terminate ***";
exit 1;;
esac
done
--------------------------------------------------------------------------------
# 3  
Old 02-03-2002
Thank you so much for helping me out.

I'm trying to write this in the C language. So far I have this:

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <iostream.h>


main()
{
cout<<"You have entered my 1814 shell"<<endl;
bool exit=true;
char *line[10];
int n=0;
getline(line[n]);
while (!(exit))
{
line[n]=0;
cout<<"READY:#";
cout<<"The command you typed was: " <<line[0];
execv(line[0],NULL);
}
}

ANYbody.....Everybody... Smilie

Last edited by jj1814; 02-04-2002 at 01:27 AM..
# 4  
Old 02-04-2002
You are welcome.

I think I encounter a strange thing.My code can run normally on sun solaris OS. I swear.

I wonder if you can tell me your platform.SCO UNIX?HP UNIX?
Perhaps the bug is caused by the version of unix OS.

I modified the code.If you input the "exit",You can quit the shell.

-------------------------------------------------------------------
#!/usr/bin/ksh

agreed=
while [ x$agreed = x ];
do
printf "Ready:$>"
read receive
if [ "$receive" = "exit" ]
then
exit 1;
fi
ksh -c "$receive"
done
--------------------------------------------------------------------
# 5  
Old 02-04-2002
it's running on Sun OS 5.8
# 6  
Old 02-06-2002
Your program is writed in C Plus Plus language,not C .
But I think there are some problems with it. I modifed your code according to your thinking.

----------------------------------------------------------
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <iostream.h>

#include <string.h>

main()
{
cout<<"You have entered my 1814 shell"<<endl;
bool exit=true;
char line[1024]; /* Command String */
int n=0;

while ((exit))
{
cout<<"READY:#";
int iRet;
cin.getline(line,sizeof(line));
/* If you input "exit",you will quit the shell */
if(strcmp(line,"exit") == 0){
cout<<"*** Shell End ***"<<endl;
break;
}
system(line);
cout<<"\n";
cout<<"The command you typed was : "<<line<<endl;
cout<<"\n";
line[0] = 0;
}
}

-------------------------------------------------------------------------
# 7  
Old 02-07-2002
:-)

thanks for everything. A version I wrote the other day works, and yours works even better. Now i'm having trouble with a daggone fork and execve command. it works, but not perfectly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

2. Programming

A simple C program query ...

Given the following code inside the function ext3_write_super(): (It's there in Linux kernel 2.6.27.59) static void ext3_write_super (struct super_block * sb) { if (mutex_trylock(&sb->s_lock) != 0) BUG(); sb->s_dirt = 0; } The conditional test at if... (2 Replies)
Discussion started by: Praveen_218
2 Replies

3. UNIX for Dummies Questions & Answers

Help with creating a simple program!!

i am new to shell scripting!! i am making this program in bourne shell, that asks the user to input "Hello (their name)" or "question (their name)", any other input, "ERROR" will be outputted. if they input "Hello (name)", i want to out saying Hello (name) but if they input "question (name)", i... (4 Replies)
Discussion started by: bshell_1214
4 Replies

4. Shell Programming and Scripting

Help with simple program. (beginner)

Hey all, Writing a program that searches for a username and if they are online creates a 'beep' and sends the username and date to a log file. the error i am getting is: paul.obrien16@aisling:~/os$ bash checklogin : command not found Enter username paul.obrien16 ': not a valid... (2 Replies)
Discussion started by: sexyladywall
2 Replies

5. Shell Programming and Scripting

simple program help required

The circumfrence of a circle is #!/usr/bin/perl print 2 * 3.141592654 * 12.50 \n"; # pi= 3.141592654 # r= 12.50 I need a simple program showing me all the steps..to modify the above to prompt for and accept a radius from the person running the... (3 Replies)
Discussion started by: Q2wert
3 Replies

6. UNIX for Dummies Questions & Answers

What's wrong with this simple program in APUE?

I start wetting my toes in Linux programming. I tried the first program myls.c in Advanced Programming in the Unix Environment. #include <sys/types.h> #include <dirent.h> #include "apue.h" int main(int argc, char *argv) { DIR *dp; struct... (1 Reply)
Discussion started by: cqlouis
1 Replies

7. Programming

Xlib simple program.

I don't know if it is right to ask you this. Can someone help me write a simple Xlib program,with button on it,and all that button do is switch 2 messages. I have tried and tried,but never get past Hello World. Can someone help me please? ---------- Post updated at 10:17 PM ---------- Previous... (2 Replies)
Discussion started by: megane16v
2 Replies

8. Programming

a simple chat program

any suggestions on how i could create a simple chat program between two terminals using pipes? thanks (1 Reply)
Discussion started by: kelogs1347
1 Replies

9. UNIX for Dummies Questions & Answers

Ok simple question for simple knowledge...

Ok what is BSD exactly? I know its a type of open source but what is it exactly? (1 Reply)
Discussion started by: Corrail
1 Replies

10. Programming

Simple Network Program Difficulties

I'm trying to write 2 programs, client & server, that communicate with integers, however, all resources I have found on the net assume that you want to send and recieve information as a character array. I don't want to send my integers as characters, I want to send them as ints (casting them to... (2 Replies)
Discussion started by: Mistwolf
2 Replies
Login or Register to Ask a Question