Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8407039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:16:30+00:00 2026-06-09T23:16:30+00:00

When I do something like: ./foo -uxw –bar something Does the shell automatically parse

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:16:31+00:00Added an answer on June 9, 2026 at 11:16 pm

    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.

    #include <stdio.h>
    
    int main(int argc, char **argv)
    {
        int i;
        printf("argc: %d\n", argc);
        for (i = 0; i < argc; i++) {
            printf("argv[%d] = %s\n", i, argv[i]);
        }
        return 0;
    }
    

    Let us compile this program.

    susam@nifty:~$ gcc args.c -o args
    

    Now let us run this and see the output:

    .susam@nifty:~$ ./args
    argc: 1
    argv[0] = ./args
    susam@nifty:~$ ./args foo bar
    argc: 3
    argv[0] = ./args
    argv[1] = foo
    argv[2] = bar
    susam@nifty:~$ ./args -a foo --b bar
    argc: 5
    argv[0] = ./args
    argv[1] = -a
    argv[2] = foo
    argv[3] = --b
    argv[4] = bar
    

    The only thing the shell does is pass each argument you specify in the command line to your program. While it would pass foo bar as 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:

    susam@nifty:~$ ./args -a foo bar
    argc: 4
    argv[0] = ./args
    argv[1] = -a
    argv[2] = foo
    argv[3] = bar
    susam@nifty:~$ ./args -a "foo bar"
    argc: 3
    argv[0] = ./args
    argv[1] = -a
    argv[2] = foo bar
    susam@nifty:~$ ./args -a 'foo bar'
    argc: 3
    argv[0] = ./args
    argv[1] = -a
    argv[2] = foo bar
    susam@nifty:~$ ./args -a "foo bar" 'car tar war'
    argc: 4
    argv[0] = ./args
    argv[1] = -a
    argv[2] = foo bar
    argv[3] = car tar war
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some nested datastructures, each something like: [ ('foo', [ {'a':1, 'b':2}, {'a':3.3,
it appears if you have something like var my_var = {foo : bar}; in
I have a string something like: foo title:2012-01-01 bar Where I need to get
Let's say I have SELECT name FROM table which gives me something like foo
I have a repository that looks something like this: foo/ subrepo/ a_file_in_subrepo another.ext unrelated_file
I have the following bash script: #DIR is something like: /home/foo/foobar/test/ without any whitespace
I want something like the following: foo.should_receive(:bar).with(an_instance_of(Bla))..... Is this possible? Edit: According to the
I'm trying to do something like var=0 grep foo bar | while read line;
I have a directory structure that looks like: Foo::Bar::Baz::1 Foo::Bar::Baz::2 etc Can I list
I have a makefile, with two variables like this OS = foo.o bar.o baz.o

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.