I use popen
to execute type -t type
, this give me an error message -t
not found. When I perform type -t type
in the shell this gives me builtin . Why doesn't this work with popen
?
POSIX specifies that the shell used with popen
is /bin/sh
. Your interactive shell is probably bash
. The behaviour of the type
command is different for sh
and bash
. sh
does not support -t
.
Your system probably has /bin/sh
symbolically linked to /bin/dash
, but that's just an implementation detail.
If you need bash
behaviour, run bash
explicitly:
popen("/bin/bash -c 'type -t type'", "r")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.