Ellebasi Ellebasi - 2 months ago 16
Bash Question

Using type -t command in linux c.?

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
?

Answer

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")

Live demo.