I’m attempting to find out how to use sh -c or bash -c properly.
I can easily run a simple command like "sh -c ls" without arguments.
The problem comes when I’m trying to add in arguments.
To do ls -ltga, I’ve had to do:
sh -c "ls -ltga"
This wouldn’t be a big issue, except I’m attempting to write my own small shell program,
and when I use execve I try:
Argument #: string
0: sh
1: -c
2: "ls
3: -ltga"
And it gives me an error, saying that it reached an EOF before finding the next '"'
I’ve also tried:
0: sh
1: -c
2: "ls -ltga"
and it returned to me saying that it couldn’t find the file/script named "ls -ltga"
Does anybody know what I am doing wrong?
You shouldn’t put quotes inside arguments of
execve(). It should be called like this:The first argument to
execve()must be the path to the executable (usually a full path).