简体   繁体   English

history命令如何仅将unix命令发送到用C编程的shell中的历史文件

[英]how does the history command send only unix commands to the history file in a shell programmed in C

I have an assignment that requires me to create a history command, and I am stuck trying to figure out how the program would recognize that the input is a Unix command then send it to a file. 我的一项作业要求我创建一个历史命令,而我一直试图弄清楚程序如何识别输入是Unix命令,然后将其发送到文件。 If a user types junk, then it would not be sent to the history file; 如果用户键入垃圾,则不会将其发送到历史记录文件; but if they type something like date , that would be sent to the history file. 但是,如果它们键入类似date ,则将其发送到历史记录文件。

You have to "look" into the environment variable PATH, and if the first word of the command correspond to a program that's inside the PATH, or (if it begin with a "/" and the program exist), you write that to the file. 您必须“查看”环境变量PATH,并且如果命令的第一个单词对应于PATH内的某个程序,或者(如果它以“ /”开头并且该程序存在),则将其写入到文件。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM