📄 myshell.c
字号:
/* 操作系统练习1: myshell.c 姓名: 杨富强 学院:通信工程 学号:01051312 在Ubuntu7.10和cygwin下已经测试通过*/
#include "myshell.h"
int main (int argc, char *argv[]){
char buf [MAX_BUFFER], pwd [MAX_ARGS]; // line buffer
char shell_path[MAX_ARGS]="shell=";
char readme_path[MAX_ARGS]="readme_path="; char newpath[MAX_ARGS*1000]; int len; strcpy(newpath,getenv("PATH")); strcat(newpath,":"); if(strcmp(argv[0],"./myshell")&&strcmp(argv[0],"myshell")) { len=strlen(argv[0]); while(len&&argv[0][len]!='/') len-- ; argv[0][len]='\0'; strcpy(pwd,argv[0]); get_fullpath(pwd, argv[0]); printf("%s\n",pwd); } else strcpy(pwd ,getenv("PWD")); strcat(newpath,pwd); // strcat(newpath,getenv("PWD")); setenv("PATH",newpath,1);// add the current working directory in the "PATH" environment variable to search for the filename specified.
strcat(shell_path,pwd); // strcat(shell_path, getenv("PWD"));
strcat(shell_path,"/myshell");
putenv( shell_path); //add the working directory of myshell in the environment variables
strcat(readme_path, pwd); // strcat(readme_path, getenv("PWD"));//
strcat(readme_path,"/readme");
putenv(readme_path); // add the filepath of the file "readme" in the environment variables, see function my_help( ) !
if(argc>1) // 也许用户直接在终端输入 ./myshell a.bat >c.txt
{
strcpy(buf,"myshell ");
int i;
for(i=1;i<argc;i++)
{
strcat(buf,argv[i]);
strcat(buf," ");
}
Execute(buf);// execute this command, 执行这个批处理命令
}
else // 如果用户在终端输入 ./myshell
{
my_clear( ); fprintf(stderr, "Welcome Enter myshell!\nType \"help\" to see the help information.\n");
my_shell(stdin,NULL,NULL);
}
return 0 ;
} // end function "main"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -