When I do something like:
./foo -uxw --bar something
Does the shell automatically parse these commands, or does each program have to do the parsing itself?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, the shell doesn’t parse it for you. Each program has to parse it on its own. The following code should make it clear what is going on.
Let us compile this program.
Now let us run this and see the output:
The only thing the shell does is pass each argument you specify in the command line to your program. While it would pass
foo baras two separate arguments to your program, it would pass"foo bar"or'foo bar‘ as a single argument to your program. Yes, so the shell does some sort of parsing of the arguments before passing it to your program. It considers quoted strings as a single argument. Here is a demonstration: