【问题标题】:how can i fire history command from c program/shell script?如何从 c 程序/shell 脚本触发历史命令?
【发布时间】:2015-12-30 07:50:03
【问题描述】:

我尝试使用 C 编程,但出现错误“sh: 1: 历史:未找到”。
我的c编程代码

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

【问题讨论】:

    标签: shell terminal command


    【解决方案1】:

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

    bash -ic 'tail -20 $HISTFILE'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-29
      • 2012-01-25
      • 2014-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 2015-07-01
      相关资源
      最近更新 更多