想到自己的好多图片还有代码在上一次硬盘挂掉的时候丢失, 心中就是阵痛...
这个简单的shell代码被放在临时的pdf文档中得以被保留了下来... 阿门...今天想写个简单的数据库的时候, 感觉是不是要做个交互页面, 不让用户写程序, 模仿MySQL简单的命令, 用户傻瓜化就好了...
交互的方式可以是shell. 其实中科院孟宁老师的一个OO课的前几课的一个小作业就是自己写个shell. 不难. RTFSC
于是... demo如下:
/**********************************************
file:shell_jason.c
code writer :EOF
code date:2014.05.13
e-mail:jasonleaster@gmail.com
**********************************************/
#include <stdio.h>
#include <stdlib.h>
char command[1024] = {0,};
int main()
{
printf("\t\t---------shell just for fun-------\t\n\n");
printf("\t\tIf you don't know what you can do, just input help ^_^\n\n");
printf(":) #--> ");
scanf("%s",command);
while(strcmp(command,"exit"))
{
if(!strcmp(command,"cd"))
{
system("cd");
}
else if(!strcmp(command,"vim"))
{
system("vim");
}
else if(!strcmp(command,"ls"))
{
system("ls");
}
else if(!strcmp(command,"date"))
{
system("date");
}
else if(!strcmp(command,"help"))
{
printf("\n\tYou could input command like:cd,vim,ls and date."
" This shell was writed just for fun. "
" It would let you know what the shell is."
" Just enjoy it.\n"
" Thank you!\n\t"
" Jason Leaster\n\n");
}
else
{
printf("Sorry, I just a naive penguin\n");
}
printf("\n:) -->");
scanf("%s",command);
}
return 0;
}
日落黄昏的小情调~ 摄于9月21日 暑假 晚7点