我如何从c程序/ shell脚本中激活历史命令?

时间:2015-10-02 06:09:02

标签: shell terminal command

我试过C编程,但这给出了错误" sh:1: 历史:未找到"。
我的c编程代码

int main ()
{
   char command[50];
   strcpy( command,"history | tail -20" );
   system(command);
   return(0);
}

1 个答案:

答案 0 :(得分:0)

bash中,您可以访问环境变量$ HISTFILE。使用参数-ci调用shell。 -c运行命令并-i为shell提供包含所有可用环境变量的交互式环境。

bash -ic 'tail -20 $HISTFILE'
相关问题