Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BASH : Difference between '-' and '--' options

Tags:

linux

bash

shell

sh

ls

I was working my way through a primer on Shell (Bash) Scripting and had the following doubt :

  • I came across the ls command

  • The man page of ls lists a few use cases as :

    ls -a
    ls --block-size='M'

My Question :

  • What is the difference in - and -- ?
  • Why are there 2 nomenclatures used ?
  • What is the motivation behind it ?
like image 246
pranav Avatar asked Feb 02 '15 14:02

pranav


1 Answers

Long-form (--foo) options are a GNU extension -- something present in GNU ls, but not present at all in the POSIX standard setting requirements for UNIX tools, so other versions of ls are not obliged to support these options. The entire word (foo) is meaningful in this case. This nomenclature was added more recently, and is more expressive than the short form (and doesn't have namespace limitations).

Short-form options (-al) are, at least in form, standardized (though extensions can add new ones). They're handled character by character, one letter at a time -- so -al means -a (show hidden files) and -l (long output), rather than having -al have its own meaning in this case. This is the original syntax for UNIX command-line options, and is thus supported not only for terseness but also for backwards compatibility.

like image 109
Charles Duffy Avatar answered Sep 29 '22 16:09

Charles Duffy