So I’m programming a basic UNIX minishell in C. Everything has been going smoothly, however I recently redid the way it parses arguments from the original string it gets from the console. Here’s an example of the way it parses:
$> echo HELLO "" WORLD!
HELLO "" WORLD!
The argument array looks like this: [echo0, HELLO0, “”0, WORLD!0]
I pass it like so:
execvp(args[0], args);
However, echo is supposed to omit quotes, and as you can see it prints them out. Since echo isn’t a builtin command in my case, I can’t customize the way it prints. Does anybody know why this might be happening? I want to omit double quotes, but include every other sort of character(besides null of course). However the empty string counts as an argument itself, so:
echo HELLO "" WORLD!
should output:
HELLO WORLD!
with 2 spaces in between, not:
HELLO WORLD!
with just one (since an empty string is an argument).
I hope this isn’t too confusing. If you guys need any clarification, please just ask; I’d be happy to post code.
It’s shell that strips quotes when parsing the command line. If you pass them to
exec*call directly, echo echoes them. It’s then equivalent toecho HELLO '""' WORLD!.