using linux command

using linux command and file

Page 1 of 1

0 Replies - 878 Views - Last Post: 29 October 2008 - 01:46 PM Rate Topic: -----

#1 shaima  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-October 08

using linux command

Posted 29 October 2008 - 01:46 PM

the assignment is require to write a C/C++ program that provides the basic operations of a command line shell. Your program should first read a command from the user (as a string of up to maximum 80 characters) and then parses it to separate the command from its (optional) switches. Your program checks that the command that has been typed by the user is a valid command (make a list of at least ten Linux commands. Any command that is not in your list should be an invalid command). If the command that is typed by the user is not a valid command then display the message “MyShell% Not a valid command”. Otherwise execute the command.

Your program should also have history feature. That is, your program should store at most last then commands. A user should be able to view these commands by typing !. A command from the history can be executed by type !n (where n is the command number in the history that the user wants to execute). Note that the history feature could be used any time, even after logging out and then logging in to your account. That means, the history should be stored permanently. Also, note that you should not have more than 10 previous commands in the history.

the code which i tried is:

#include<iostream>
using namespace std;


int main()
{

int x=0;
string history[10];
string command[20]={"ls","pwd","cat","cal","exit","cd","mkdir","rmdir","clear","date"}
string cm,fname,name;
int cm_no=-1;

cout<<"Enter your command : "<<endl;
cin>>cm;

if(strlen(cm)<=80)
{
for(i=0,i<10,i++)
{
if(cm==command[i])
cm_no=i;
history[x]=cm;
++x;
}

if(cm_no==-1)
cout<<"MyShell%Not a valid command"<<endl;

}

esle

{
cout<<"MyShell%Not a valid command"<<endl;

}


switch(cm){
case (1): // LS
cout<<endl;
system("ls");
break;

case(2): //pwd
cout<<endl;
system("pwd");
cout<<endl;
break;

case(3): //cat
cout<<"Enter file name:"<<endl;
cin>>fname;
system("cat fname");
break;

case(4): //cal
cout<<endl;
system("cal");
cout<<endl;
break;

case(5): //exit
system("exit");
break;

case(6): //cd
system("cd");
break;

case(7): //mkdir
cout<<"Enter a name: "<<endl;
cin>>name;
system("mkdir name");
break;

case(8): //rmdir
cout<<"Enter a name: "<<endl;
cin>>name;
system("rmdir name");
break;

case(9): //clear
system("clear");
break;

case(10): //date
cout<<end;
system("date");
break;
}
return 0;
}


i need your advice ... aslo its need file for the history but i don't remember how to use it ..
plz help :(

Is This A Good Question/Topic? 0
  • +

Page 1 of 1