![](/img/trans.png)
[英]Is ncurses a good choice to implement a command history in a C program in linux
[英]C-Linux-Any way to pass command “history” to Linux shell?
我正在编写一个在Linux系统中运行的C程序。 该程序将一些Linux命令传递给shell并使用txt文件接收结果。
system("last >> last.txt");
system("ls -s >>ls.txt");
但我失败了“历史”,因为有人告诉我,这不是一个命令,而是一个建筑。
那么我有什么方法可以像其他人一样传递“历史”?
谢谢!
您也可以使用shell实际调用内置命令:
system("bash -e \"history >> history.txt\"");
将"bash"
更改为首选shell。
“history”相当于“cat~ / .bash_history”,所以替代方法是使用:
system("cat ~/.bash_history");
根据使用的shell,您可以查看历史记录文件。
例如:〜/ .bash_history或〜/ .zsh_history。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.