I want to write a program which executes the Linux ls
command.
I really only want to type in ls
and not /bin/ls
, so I want to do this using execve
(execvp
is not an option).
I tried:
char *env[] = { "SHELL=/bin/bash",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games",
"_=/usr/bin/env",
(char *)0 };
execve(parmList[0], parmList, env);
But it does not seem to work, ls
is not recognized but /bin/ls
is. Nothing is wrong with parmList
because I tried this with execvp
and it worked.
Any ideas?