在 linux c. 中使用 type -t 命令?

Using type -t command in linux c.?

我使用 popen 来执行 type -t type ,这给我一个错误消息 -t not found。当我在 shell 中执行 type -t type 时,这给了我 builtin。为什么这不适用于 popen

POSIX 指定与 popen 一起使用的 shell 是 /bin/sh。您的互动 shell 可能是 bashtype 命令的行为对于 shbash 是不同的。 sh 不支持 -t

您的系统可能有 /bin/sh 符号链接到 /bin/dash,但这只是一个实现细节。

如果您需要 bash 行为,运行 bash 明确:

   popen("/bin/bash -c 'type -t type'", "r")

Live demo.