LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-27-2011, 09:44 AM   #1
Hevithan
Member
 
Registered: Apr 2011
Location: Washington State
Distribution: Zorin5-(Ubuntu 11.04) // Backtrack 5-(Ubuntu 10.04) // Dreamlinux 3.5-(Debian)
Posts: 275
Blog Entries: 5

Rep: Reputation: 39
Quick question about single/double dash commands.


This is not a technical problem, But just a general question. Hope I put it in the right category.

I was reading @ linuxcommand.org so I can learn more ... And got to the section where it explains that there are - single dash commands for single letter options (-a) and --double for long (--version). Other then explaining that they exist and how to use them, It doesn't provide much detail. What i am wondering is, Do most '-' commands have a counter part that you can use with '--', and vice versa? Such as -h and --help being used the same way? and if so are there benefits other then convenience (for times when you enter multiple options)?

It seems like a relatively trivial and pointless question, But I figure if I'm gonna try to understand how the system operates ... I should sweat the small stuff.
Thanks for any answers.

Last edited by Hevithan; 05-27-2011 at 09:45 AM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 05-27-2011, 09:48 AM   #2
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,139

Rep: Reputation: 638Reputation: 638Reputation: 638Reputation: 638Reputation: 638Reputation: 638
those arent commands but flags to options for commands...
its really at the discretion of the developer to make flags as easy to recognize.
there are some mnemonics that are kinda' standard (e.g.- -h == --help) but theyre not always followed.
the man page for the command should list what the options are so you dont need to memorize anything.
 
2 members found this post helpful.
Old 05-27-2011, 10:07 AM   #3
Hevithan
Member
 
Registered: Apr 2011
Location: Washington State
Distribution: Zorin5-(Ubuntu 11.04) // Backtrack 5-(Ubuntu 10.04) // Dreamlinux 3.5-(Debian)
Posts: 275
Blog Entries: 5

Original Poster
Rep: Reputation: 39
I'm not really trying to memorize, as much as I am trying to get a basic understanding of the hows and whys of the shell's thinking process, I am sure as I continue to read up on it I will get the info I want.
Thanks a lot for the reply and your help.

Quote:
those arent commands but flags to options for commands
Ya know, I'm aware that the proper term is option ... But for some reason I keep typing command, lol (God I hate lol but it denotes the context of humor or sarcasm pretty well) I guess I'll have to get over that.

Thanks again.
 
Old 05-27-2011, 11:06 AM   #4
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by Hevithan View Post
Do most '-' commands have a counter part that you can use with '--', and vice versa? Such as -h and --help being used the same way?
Most do, but some don't. There aren't any standards for this, it's up to that person who wrote the program.

Quote:
Originally Posted by Hevithan View Post
and if so are there benefits other then convenience (for times when you enter multiple options)?
Do you mean that -- options are more convenient or - options are more convenient?
 
Old 05-27-2011, 11:09 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,627

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
As pointed out it is more to do with how an individual developer would like to portray options to the users. This is also not strictly 'shell' thinking but more command thinking.

The short answer to your question is that, no it is not necessary to have both a single and double dash flag for each option available to a command.

I will say though that it is a lot clearer sometimes to use the double flag option.
As a simple example:
Code:
tar acf archive.tar.bz2 dir/

# compared to

tar --auto-compress --create --file archive.tar.bz2 dir/
For a layman the second is fully recognizable as to what is happening with this command, but the first would assume prior knowledge or access
to a help service like man for the beginner to fully grasp each option.
 
1 members found this post helpful.
Old 05-27-2011, 11:29 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by grail View Post
This is also not strictly 'shell' thinking but more command thinking.
Good point. From this thread (http://www.linuxquestions.org/questi...l-char-882901/), it seems like some members falsely believe that the options are interpreted by the shell. In fact, thay have nothing whatsoever to do with the shell in any way.
 
1 members found this post helpful.
Old 05-27-2011, 11:58 AM   #7
Hevithan
Member
 
Registered: Apr 2011
Location: Washington State
Distribution: Zorin5-(Ubuntu 11.04) // Backtrack 5-(Ubuntu 10.04) // Dreamlinux 3.5-(Debian)
Posts: 275
Blog Entries: 5

Original Poster
Rep: Reputation: 39
Quote:
Originally Posted by MTK358 View Post
Most do, but some don't. There aren't any standards for this, it's up to that person who wrote the program.



Do you mean that -- options are more convenient or - options are more convenient?
I meant, That if you are doing a command that has more then one option to select, It just makes sense that the single - would be less time consuming V.S. typing out full words and using --, Much like grail's example.
Quote:
Code:
tar acf archive.tar.bz2 dir/

# compared to

tar --auto-compress --create --file archive.tar.bz2 dir/

Quote:
...the options are interpreted by the shell. In fact, thay have nothing whatsoever to do with the shell...
And just to clarify so I know I understand what you've said here:

Commands = Shell
Options = Script

that's the basic deal right?

Marking this as solved, Thank you all for taking the time to give me the run down on my silly - VS -- question.
 
Old 05-27-2011, 12:11 PM   #8
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
*nix people have always been lazy and that is reflected in the standard commands. Why type 4 characters (copy) if 2 characters (cp) will do. In the same tradition, options have always been single characters; why type --archive if -a will do.

Further short options can be combined; e.g ps -ef is the same as ps -e -f but saves two characters typing.

The standard used to be short options,long options are a 'recent' development (not sure when it started).

As said, it's what the developer finds useful; I only implement short options when writing software.
 
1 members found this post helpful.
Old 05-27-2011, 12:31 PM   #9
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by Hevithan View Post
Commands = Shell
Options = Script
Commands aren't part of the shell, either*. They're executable programs on your disk. The shell is just a convenient way to launch them.

The shell is purely a program that conveniently lets users launch other programs, plus some extras like variables, conditionals, and pipes that let you automate stuff and make commands work together.

* There are a few exceptions, they're called "shell builtins". They consist mostly of commands that are so often used in scripts that implementing them in the shell makes scripts much more efficient (note that most systems still have non-builtin versions tof these commands, too), and commands that control your shell instance (so it wouldn't be practical for them to be separate executables).

Last edited by MTK358; 05-27-2011 at 12:33 PM.
 
1 members found this post helpful.
Old 05-27-2011, 07:12 PM   #10
Telengard
Member
 
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Blog Entries: 8

Rep: Reputation: 147Reputation: 147
The history of command line option syntax in Unix and its descendants is long and twisted. I haven't learned all there is to know about this history, but I have inferred much (sometimes incorrectly) from my own experience. Two good examples of this long and twisted history are the manpages for ls and ps.

In any case, check the man page and GNU info manual for details.

Quote:
Originally Posted by Hevithan View Post
What i am wondering is, Do most '-' commands have a counter part that you can use with '--', and vice versa?
It varies from command to command. Check the man page and GNU info manual for details.

Quote:
Such as -h and --help being used the same way?
Some commands support one or the other, but some support both or neither. In general, I have found it to be safe to assume all programs will provide some helpful information when given '--help', but there are exceptions.

The GNU Coreutils Manual says:

Quote:
Most programs that accept long options recognize unambiguous abbreviations of those options. For example, ‘rmdir --ignore-fail-on-non-empty’ can be invoked as ‘rmdir --ignore-fail’ or even ‘rmdir --i’. Ambiguous options, such as ‘ls --h’, are identified as such.

Some of these programs recognize the --help and --version options only when one of them is the sole command line argument. For these programs, abbreviations of the long options are not always recognized.

‘--help’
Print a usage message listing all available options, then exit successfully.
Check the program's man page and GNU info manual for details.

Quote:
and if so are there benefits other then convenience (for times when you enter multiple options)?
In general you should choose an options syntax which you understand well and is unambiguous. As you become more familiar with a command you will develop a better understanding of its option syntax. Check the man page and GNU info manual for details.

GNU programs seem to use '--long-option' more for options which weren't available on traditional Unix versions of the command. GNU programs also provide many '--long-option' formats for many options which already have well known '-x' (single hyphen followed by single letter) formats.

If I were to generalize command line option syntax I'd probably say there are two categories: binary options (on or off), and settings for internal variables.

Binary (on|off) Options

A binary option has only two possible states: on or off. A good example which is supported by most commands is verbosity. According to Unix tradition, most programs produce little or no output on the terminal unless something goes wrong. For example, rm is completely silent if the file was removed successfully.

Code:
foo$ rm infile
foo$
If you want rm to explicitly state what is being done, you can pass it the -v option.

Quote:
Originally Posted by man rm
-v, --verbose
explain what is being done
Code:
foo$ rm -v t
removed `t'
foo$
The verbose option is what I call a binary option, because it can only be either on or off. Notice that there are both short form and long form options for verbosity in many programs.

Settings For Internal Variables

Most programs use many variables internally which determine what actions are taken and how they are performed. Programmers reveal some of these variables to users through command line options. For example, consider the options for GNU date:

Quote:
Originally Posted by info coreutils 'date invocation'
‘-d datestr’
‘--date=datestr’
Display the date and time specified in datestr instead of the current date and time. datestr can be in almost any common format. It can contain month names, time zones, ‘am’ and ‘pm’, ‘yesterday’, etc. For example, --date="2004-02-27 14:19:13.489392193 +0530" specifies the instant of time that is 489,392,193 nanoseconds after February 27, 2004 at 2:19:13 PM in a time zone that is 5 hours and 30 minutes east of UTC.
Note: input currently must be in locale independent format. E.g., the LC_TIME=C below is needed to print back the correct date in many locales:

date -d "$(LC_TIME=C date)"
Code:
foo$ date
Fri May 27 17:55:15 EDT 2011
foo$ date -d "tomorrow"
Sat May 28 17:55:22 EDT 2011
foo$ date --date="next monday"
Mon May 30 00:00:00 EDT 2011
foo$
The date string is an internal variable which the date command uses to determine which date is desired. If none is specified, then the date command automatically initializes date string to now, just as if you had typed date -d "now". Alternate dates may be specified with either --date=date string (long format) or -d date string (short format).

For more information about command line options and how they are parsed you might read the manpages for man 1 getopt and man 3 getopt.

HTH
 
1 members found this post helpful.
  


Reply

Tags
command line, option


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Printf: giving "001 002 003 004 006.... 150" in a single line dash command? Xeratul Programming 6 01-16-2011 08:00 AM
single click instead of double - opening folders dianat100 Mandriva 5 10-23-2005 05:44 PM
Quick question: Learning commands Kami.JZ Linux - Newbie 4 10-24-2004 05:14 PM
Double and single quote, Question in expect evilchild Programming 4 08-22-2004 06:34 PM
What are those double-dash (--) options in man? Utah Linux - Newbie 4 06-04-2004 11:53 PM


All times are GMT -5. The time now is 09:47 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration