Thread: Difference between the words: argument, option and flag

  1. #1
    Registered User
    Join Date
    Apr 2010
    Location
    Vancouver
    Posts
    132

    Difference between the words: argument, option and flag

    Say you are typing in a termainl running the bash shell and write "ls -la /usr/bin"

    What is considered the argument, option and flag?

    Also, how does the interpreter know where the end of one is? For example are options deliminated by spaces; so if there's a space the interpreter knows it's a different option?

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    The way I understand it is these three things are arguments:
    1. ls
    2. -la
    3. /usr/bin

    The "-la" are two options, but sometimes people call them flags.

    The basic parsing a terminal can do is separate all of the strings delimited by spaces and send them to the program as an array, which is received in the implementation of the program by language-dependent means. For any other advanced parsing, like understanding that -la means two different things, you need to program it.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Quote Originally Posted by c_weed View Post
    Also, how does the interpreter know where the end of one is? For example are options deliminated by spaces; so if there's a space the interpreter knows it's a different option?
    As mentioned spaces delimit arguments so if you need to include a space in the argument you normally need to quote it in your shell, for example

    ls -l "Program Files"

    If an argument begins with a "-" and it is not a flag you cannot quote it because the program itself sees the - and might think it is a flag. In that case you can usually do something like this instead:

    ls -l "./-file-beginning-with-a-dash"

    If the tool you are using does GNU style options processing then the following also works (the "--" marks the end of the options, so that all the remaining arguments are considered non-option arguments)

    ls -l -- "-argument-beginning-with-a-dash"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 12-10-2012, 12:24 AM
  2. GCC -g vs -g3 Flag: What is the Difference?
    By haziz in forum C Programming
    Replies: 1
    Last Post: 05-06-2012, 05:22 PM
  3. Template Argument inside the Argument of a Function Declaration
    By manasij7479 in forum C++ Programming
    Replies: 3
    Last Post: 06-11-2011, 05:53 AM
  4. Replies: 7
    Last Post: 10-01-2010, 04:09 PM
  5. problem passing an option as command line argument
    By papous in forum C Programming
    Replies: 3
    Last Post: 11-22-2001, 06:12 PM