Questions
I would like to execute the Linux command "pwd" through a C language function like execv().
The issue is that there isn t an executable file called "pwd" and I m unable to execute "echo $PWD", since echo is also a built-in command with no executable to be found.
Answers
You should execute sh -c echo $PWD; generally sh -c will execute shell commands.
(In fact, system(foo) is defined as execl("sh", "sh", "-c", foo, NULL) and thus works for shell built-ins.)
If you just want the value of PWD, use getenv, though.
Source
License : cc by-sa 3.0
http://stackoverflow.com/questions/19209141/how-do-i-execute-a-shell-built-in-command-with-a-c-function
Related