myshell

所属分类:操作系统开发
开发工具:C/C++
文件大小:279KB
下载次数:123
上传日期:2010-11-04 20:13:27
上 传 者honghere
说明:  《操作系统—精髓与设计原理》一书中myshell编程项目,代码写得很清晰,纠错能力很强大,实现了基本的内部命令:cd、dir、help、echo、environ等,以及实现文件重定向、后台处理等功能。附有实验报告。
(" Operating system- the essence and principles of design" , a book myshell programming projects, the code is written very clear, very strong error correction ability to achieve the basic internal commands: cd, dir, help, echo, environ, as well as re-implementation file orientation, background processing and other functions. With a test report.)

文件列表:
myshell_for_linux\makefile (188, 2008-06-17)
myshell_for_linux\myshell.c (2118, 2008-06-17)
myshell_for_linux\myshell.h (2265, 2008-06-17)
myshell_for_linux\utility.c (40643, 2008-06-17)
操作系统实验报告.doc (371200, 2009-04-27)
myshell_for_linux (0, 2010-11-02)

myshell 1.0 Operating System ---- Project 1 Copyright@Yang Fuqiang ID:01051312 myshell supports the following internal commands: cd clr dir echo environ help myshell pause pwd quit And the executive external file can be executed too, just like external commnads. Type "help more" to see the whole user manual,or you can seek the help information as the following themes: "help command" ---see the internal commands; "help shell"---see more detail about this shell; "help help" ---see the usage of 'help' command; "help bat"---see how the shell execute from a batchfile; "help i/o redirection"---learn about the i/o redirection; "help background"---learn about the background mode; "help path"---see the format of filepath or dirpath. # The Shell or Command Line Interpreter is the fundamental user interface to an Operating System. The shell: * interprets the input, * takes appropriate action, and * finally prompts for more input. The shell can be used either * as interactively - enter commands at the command prompt, or * as an interpreter to execute a shell script. # Code of myshell is writen in 'straight' C using the compiler of gcc. Myshell has been debugged in Ubuntu 7.10, and it can be implemented on the specifed UNIX platform. However, myshell is just a simple shell --- that has the following properties: ************************* Internal commands ********************** ********************************************************************* myshell supports the following internal commands: cd clr dir echo environ help myshell pause pwd quit And the executive external file can be executed too. Type "help [command]" to get the detail usage of each command. e.g. help dir # ************************ Script file support ********************* ********************************************************************* myshell is able to take its command line input from a batchfile. i.e. if the shell is invoked with a command line argument: e.g. myshell a.bat then the batchfile -- a.bat -- is assumed to contain a set of command lines for the shell to process. When the end-of -file is reached, the shell should exit. Obviously, if the shell is invoked without a command line argument it solicits input from the user via a prompt on the display. See also "help myshell". # ************************ I/O Redirection *********************** ****************************************************************** Some times when the arguments to a command is too many that you may waste a lot of time to type them from the keyboard. Fortunately, input redirection allows you to assign the arguments from a file. On the other hand, you can output the executoion results into a file instead of displaying them in screen. This is called output redirection. In a word, I/O Redirection allows you to use inputfile and outputfile to replace the standard input(keyboard) and standard output(screen) respectively. myshell supports i/o-redirection on either or both stdin(standard input) and/or stdout(standard output). i.e. the command line: e.g. programname arg1 arg2 outputfile this will execute the program programname with arguments arg1 and arg2, the stdin FILE stream replaced by inputfile and the stdout FILE stream replaced by outputfile. The file can be given by the full path as: /home/username/a.txt As to the file path format, type "help path" to get more information. Input redirection --i.e. stdin redirection-- is possible for the internal commands: cd, dir, echo. Output redirection --i.e. stdout redirection-- is possible for the internal commands: dir, environ, echo, help, pwd. * when the redirection token is < then the inputfile is opened if it exists, or a "Path Error" wil be reported in the screen. e.g. cd then the outputfile is created if it does not exist and truncated if it does. e.g. ls >a.txt * when the redirection token is >> then outputfile is created if it does not exist and appended to if it does. e.g. environ >>a.txt Sometimes you can use more than one token to open several files as input or/and output. e.g. echo n.txt dir >m.txt >n.txt If the file cannot opened due to read permission or write permission, an "Open Error" wil be reported in the screen. # ************************ Background Execution ****************** ******************************************************************** Normally, when a command is execution, you have to wait for the completion and type another command. Especially, when the comand is executed from a batchfile, much time is wasted in waiting. Background execution allows you not to wait for the execution. An ampersand (&) at the end of the command line indicates that the shell should execute the command in background. myshell supports background execution of programs. An ampersand (&) at the end of the command line indicates that the shell should return to the command line prompt immediately after launching that program. # ******************* Detail usage of each command ************** ******************************************************************* Format: cd [directory] -- change the current default directory to [directory]. e.g. cd /home This command also change the PWD environment variable (use the command "pwd" to see it). As to the directory path, type "help path" to get more information. If the [directory] argument is not present, report the current directory. If the directory does not exist, a "Path Error" wil be reported in the screen. Moreover, you can use a directory path writen in a file as: e.g. cd Format: clr or clear -- clear the screen, no arguments is needed. # Format: dir [directory] -- list the contents of directory [directory] e.g. dir /home This command is different from "cd", it change neither the current default directory nor the PWD environment variable(use the command "pwd" to see it). As to the directory path, type "help path" to get more information. If the [directory] argument is not present, list the contents of the current directory. If the directory does not exist, a "Path Error" wil be reported in the screen. Moreover, you can use a directory path writen in a file as: e.g. dir b.txt or dir >b.txt >c.txt The token ">" can be replaced by ">>", type "help redirection" to see the difference of ">" and ">>". You can use both input redirection and output redirection as: e.g. dir b.txt >c.txt The file can be given by the full path as: dir Format: environ -- list all the environment strings in screen or into one file or more than one file as: e.g. envieron or environ >b.txt or environ >b.txt >c.txt The token ">" can be replaced by ">>", type "help redirection" to see the difference of ">" and ">>". The file can be given by the full path as: /home/a.txt As to the file path format, type "help path" to get more information. # Format: echo [comment] -- display [comment] on the display or output files followed by a new line. And multiple spaces/tabs will be reduced to a single space. e.g. echo hello world The words "hello world" will display in the screen. [comment] can be multiple words either typed from keyboard or read from one or more input files. e.g. echo c.txt or echo hello world >c.txt >d.txt The token ">" can be replaced by ">>", type "help redirection" to see the difference of ">" and ">>". You can use both input redirection and output redirection: e.g. echo c.txt >d.txt The file can be given by the full path as: echo /home/b.txt As to the file path format, type "help path" to get more information. # Format: help or ? -- display the user manual. Type "help [command]" to get the detail usage of a command as: e.g. help dir or ? dir Type "help command" to see the internal commands. And you can display or output the help information into one file or more than one file as: e.g. help dir >c.txt or help dir >c.txt >d.txt The token ">" can be replaced by ">>", type "help redirection" to see the difference of ">" and ">>". The file can be given by the full path as: help dir >/home/a.txt As to the file path format, type "help path" to get more information. # Format: myshell batchfile or myshell c.txt or myshell a.bat >c.txt >d.txt The token ">" can be replaced by ">>", type "help redirection" to see the difference of ">" and ">>". The file can be given by the full path as: e.g. myshell /home/username/b.txt As to the file path format, type "help path" to get more information.then put results in outputfile. # Format: pause -- display "Press Enter to continue..." and pause operation of the shell until the 'Enter' key is pressed (ignore any intervening non-'Enter' input). # Format: pwd -- show the PWD environment variable. If you want to list all the environment strings, use command "environ", type "help environ" to see. You can display or output the execution results into one file or more than one file as: e.g. pwd a.bat >c.txt or pwd a.bat >c.txt >d.txt The token ">" can be replaced by ">>", type "help redirection" to see the difference of ">" and ">>". The file can be given by the full path as: e.g. pwd >/home/a.txt As to the file path format, type "help path" to get more information.then put results in outputfile. # Format: quit or exit -- Exit myshell, no argument is needed. # ********************* Directory path and File path****************** ************************************************************************* .. . and ~ can be used in pathnames. .. stands for the parent directory of the current working directory, . stands for the current working directory, ~ stands for the home directory. If the filename or directoryname contains a white space, type "\ " : e.g. echo
近期下载者

相关文件


收藏者