⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme

📁 这是一个linux下的Shell.有命令历史和命令提示
💻
字号:
无关的话:	这时一个简单的Shell程序.我叫她lover.我希望她能像一个体贴的情人一样理解你的意思lover是如何工作的:一.查找命令的循序?1).以"/", "~/"开头输入的输入, 认为是绝对路径就在这个路径下查找.如果找不到可执行的文件,就把第一个找到的文件作为一个Shell的脚本文件.如果没有一个文件被找到,则提示找不到你要的命令.2).其他.以下都在找到第一个可执行的文件是结束.如果没有找到,则按2,3的顺序找到第一个文件作为一个Shell的脚本文件.如果没有一个文件被找到,则提示找不到你要的命令.1>lover的命令.包括cd,pwd,path,his,tip2>PATH所指定的目录下3>当前目录下.二.如何给程序传递参数?1).如果以 -  开头,则将 - 及其后面的字符串不作任何修改就传递,2).其他的则在当前目录下或其指定的目录下找匹配的文件.将文件的相对路径作为参数.如果没有匹配的文件,就把你的输入作为参数.3).以"/", "~/"开头输入的输入, 认为是绝对路径就在这个路径下查找, 将查到匹配的文件的绝对路径传为参数.特殊字符集:* ? [ - ] ! ~\ ; ' "| & > <'\t' ' '(空格符) 各个特殊字符的意义.* ? [ - ] ! 为通配符. [注意: 匹配通配符除有按照其特定的意义外还要考虑到用户的经验.如*表示匹配0都多个任意字符.ls * 用户的想法应该是列出当前路径的所有文件.但 .. 是匹配 * 的.所以会列出上一级目录的内容.这时用户没有料到的.按照最小惊愕原则,我去掉了.. .如果用户输入的是rm * ,lover 把上一级的文件也删掉了,问题就到了.]~表示用户的主目录.仅在~为一个单独的block,或~后为/才按照特殊字符解释.如果一个block的第一个字符为-,那么这个字符串内的特殊字符除了\外都不解释.\为转意字符表识符.如果解释\那么\后的任何特殊字符都不解释.从左到右的第一个\是特殊字符,要解释.;为分隔命令字符.'为连接字符.' '之间的除了\和通配符外其他特殊字符都不解释.""为命令取代字符下列\特殊字符在' '之间都不解释. |   为管道字符. >  为输出重定向字符>> 为输出追加重定向字符<  为输入重定向字符& 为表示在后台运行字符	如果可以使用引用我就尽量使用引用,而不使用指针.虽然引用和指针在本质上是一样的,但编译器对引用的类型要求高一些.所以引用可以保证都是有效的,而指针肯可能是无效的.	lover中有打量的内存操作.因为用户的输入是不确定的,所以用大量的动态分配和释放内存.为了通一和减少出错起见,我按照下面的规则处理指针.(记调用者为caller,函数为func,作为参数的指针为ptr,作为返回值的指针为ptr_ret)	内存操作的一些经验1."谁分配内存,谁释放"2."谁占有内存,谁释放"3."指向动态分配的内存的指针要尽可能的少.最好只有一个."4."动态分配的内存中,尽可能不要有指针"(完全的"谁分配,谁释放"是很难做到的)(1).	不论ptr所指向的内存是否是动态分配的func都不释放.除了free__(char** buf)和free__(char**buf, int num)因为它们的功能就是释放内存.调用free__的caller自己保证buf指向一个动态分配的内存而且没有被释放.(2)	ptr_ret所指向的或者是0, 或者是动态分配的内存, 或者是就是ptr所指的内存,但是起始地址不同.即ptr_ret >= ptr && ptr_ret < ptr + strlen(ptr). 这有个限制就是ptr所指向的内存是不能修改的.func一般是个查找函数.(3)	如果一个对象存储指针, 那么它不真的存储指针传来的指针(无论是push还是inset), 而是动态分配一块相同打下的内存,然后做一份拷贝. Stack_ext 和 List 就是这样. 注意容易出错的地方:	strlen返回值是无符号整数,如果要用strlen比较两个字符串的长短,要强制转换为int类型.//这时网上找到的翻译过的Bash的文档的一部分.Definitions(定义)  ***********      These definitions are used throughout the remainder of this manual.   下面的这些定义将在本指南的其余部分使用到。   `POSIX'       A family of open system standards based on Unix.  Bash is       concerned with POSIX 1003.2, the Shell and Tools Standard.       基于开放系统标准的规范集。Bash与POSIX 1003.2,Shell和Tools标准有关。   `blank'(间隔符)       A space or tab character.(空格或制表符) 					[lover的间隔符还包括 ; 用于间隔不同的命令] `builtin'(内建命令)  								[lover的内建命令有cd, his, pwd, path, exit]     A command that is implemented internally by the shell itself,       rather than by an executable program somewhere in the file system.       由shell自身在内部实现的,而不是有文件系统中的某个可执行程序实现的命令。   `control operator'(控制符)       A `word' that performs a control function.  It is a `newline' or       one of the following: `||', `&&', `&', `;', `;;', `|', `(', or `)'.       具有控制功能的一个word,可以是一换行符或下面的字符中的某一个:||,&&,&, ;,;;,(,)。   `exit status'(退出码)       The value returned by a command to its caller.       命令返回给其调用者的值。   `field'(字段)       A unit of text that is the result of one of the shell expansions.       After expansion, when executing a command, the resulting fields       are used as the command name and arguments.       是某个shell展开结果的一段文字。展开后,在执行命令时,结果字段被用于作为命 令名和命令变元。   `filename'(文件名)       A string of characters used to identify a file.(用于标识一个文件的字符串  `job'(作业)       A set of processes comprising a pipeline, and any processes       descended(从...传下来) from it, that are all in the same process  group.       组成管道的进程集合,或任何从其中分离出的在同一进程组的任何进程。   `job control'(作业控制)  								[lover 没有作业控制]     A mechanism by which users can selectively stop (suspend) and       restart (resume) execution of processes.       一种机制,可允许用户选择停止(暂停)进程和重新启动(重新执行)进程继续执 行。   `metacharacter'(元字符)       A character that, when unquoted, separates words.  A metacharacter       is a `blank' or one of the following characters: `|', `&', `;',       `(', `)', `<', or `>'.       在未被引号括起时作为分离单词的字符。元字符可以是一个间隔符或下面的某一个 字符:|,&,;,(,),<,>。   `name' (名)       A `word' consisting solely of letters, numbers, and underscores,       and beginning with a letter or underscore.  `Name's are used as       shell variable and function names.  Also referred to as an       `identifier'.       仅由字母,数字,以及下划线组成的word,且以字母或下划线开头。name被用作 shell变量和函数名称。也叫标识符(identifier)。   `operator'(操作符)       A `control operator' or a `redirection operator'.  *Note       Redirections::, for a list of redirection operators.       控制符或重定向符。   `process group'(进程组)       A collection of related processes each having the same process group  ID.       具有相同进程组ID的相关进程集合。   `process group ID'(进程组ID)       A unique identifer that represents a `process group' during its  lifetime.       用于在进程组生命期间表示进程组的唯一的标识符。   `reserved word'(保留字)       A `word' that has a special meaning to the shell.  Most reserved       words introduce shell flow control constructs, such as `for' and       `while'.       对shell具有特殊含义的word。多数保留字引入shell流程控制结构,如for和while  `return status'(返回码)       A synonym(同义字) for `exit status'.(退出码的同义字)   `signal'(信号)       A mechanism by which a process may be notified by the kernal of an       event occurring in the system.       一种核心通知进程在系统中有事件发生的机制。   `special builtin'(特殊内建命令)       A shell builtin command that has been classified as special by the       POSIX.2 standard.       根据POSIX.2标准分类的特殊的shell内建命令。   `token'(标记)       A sequence of characters considered a single unit by the shell.       It is either a `word' or an `operator'.       被shell作为一个独立实体的字符序列。可以是word或操作符。   `word'       A `token' that is not an `operator'.(非操作符的标记。)    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -