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!!!!
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
--------------------------------------------------------------------------------
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...
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
--------------------------------------------------------------------
it's running on Sun OS 5.8
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;
\}
}
-------------------------------------------------------------------------
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.
What's wrong?
i posted my new problem under the "Fork()ing Hell!" thread. you can read allllll about it there