Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从c程序/shell脚本中激发历史记录命令?_Shell_Terminal_Command - Fatal编程技术网

如何从c程序/shell脚本中激发历史记录命令?

如何从c程序/shell脚本中激发历史记录命令?,shell,terminal,command,Shell,Terminal,Command,我尝试使用C语言编程,但这会产生错误“sh:1: 历史记录:未找到。“ 我的c编程代码 int main () { char command[50]; strcpy( command,"history | tail -20" ); system(command); return(0); } 在bash中,可以访问环境变量$HISTFILE。使用参数-ci调用shell-c运行命令,并-i为shell提供一个包含所有可用环境变量的交互式环境 bash -ic 'tail

我尝试使用C语言编程,但这会产生错误“sh:1: 历史记录:未找到。“
我的c编程代码

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

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

bash -ic 'tail -20 $HISTFILE'