Unix 调用popen时,哪个shell将执行cmd

Unix 调用popen时,哪个shell将执行cmd,unix,ansi-c,Unix,Ansi C,首先,请原谅我糟糕的英语 这是原型 FILE *popen(const char* cmd_string, const char* type); 这是我的问题,这本书说当调用popen函数时,它会调用exec来获取一个shell来执行我们给popen的cmd_字符串,但我不确定exec将获取哪个shell,所以有人能给我一个答案吗?/p>/bin/sh:来自文档: The command argument is a pointer to a null-terminated string

首先,请原谅我糟糕的英语

这是原型

FILE *popen(const char* cmd_string, const char* type);

这是我的问题,这本书说当调用popen函数时,它会调用exec来获取一个shell来执行我们给popen的cmd_字符串,但我不确定exec将获取哪个shell,所以有人能给我一个答案吗?

/p>/bin/sh:来自文档:

   The command argument is a pointer to a null-terminated string
   containing a shell command line.  This command is passed to /bin/sh
   using the -c flag; interpretation, if any, is performed by the shell.
让我们试试看:

$ cat test.c
#include <stdio.h>

int main() {

  FILE *fp;
  char var[5];

  fp = popen("echo $0", "r");
  fgets(var, 5, fp);
  printf("%s", var);
}
$ gcc -Wall test.c
$ ./a.out
sh
$cat test.c
#包括
int main(){
文件*fp;
char-var[5];
fp=popen(“echo$0”、“r”);
fgets(var,5,fp);
printf(“%s”,var);
}
$gcc-墙壁测试.c
美元/年
嘘

非常感谢,我现在明白了,这真的很有帮助,再次感谢