You can ask the shell to execute the command for you using the -c option.
If the command is an inline shell or a shell script, the shell will run it; if it is an external command, the shell will execute the binary.
Try this and see if it works for you:
execl("/bin/sh", "/bin/sh", "-c", path, (char*) 0);
EDIT: fixed the above call. This should work now; I tested with
execl("/bin/sh", "/bin/sh", "-c", "set", NULL);
and my test program repeated shell variables. Then I tested with
execl("/bin/sh", "/bin/sh", "-c", "/usr/bin/clear", NULL);
and my test program cleared the terminal emulator screen.
NOTE. The good thing about this answer is that it will run everything that you can run from the shell. This way it will run shell built-in commands, and it will run shell scripts that don't have the correct #!/path/to/interpreter first line. If all shell scripts you ever want to run have the correct #! first line, you do not need it. This offers a slightly more reliable solution due to the execution of the shell, which may not be needed.
source share