![](/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.