General specification for command line interface

  1. I was wondering where I can find and
    learn some general idea about the
    command line interface used in Linux
    and bash?
  2. As to now, I have found pieces of
    such information only from
    experience, such as

    1. For cat, without any further
      arguments, it accepts stdin input.
      But you may explicitly specify STDIN
      using the special name -, and both
      ways are equivalent. cat can also
      accept a filename as cat filename.
      So is - meant to fill in an
      argument supposed for filename? Is
      this usage of - also common for
      other commands?
    2. In chardet <<<somestring, <<<
      means a string is used as stdin,
      the same as echo somestring |
      chardet
      . Is this usage of <<<
      also common?
    3. In cut -c 1-3,20,25- employees, is
      the way 1-3,20,25- to specify a
      range of numbers for an argument
      also common in other commands?
  3. Last but not least, are these
    general ideas common to just within
    bash, or within Linux and Unix, or
    within software using getopt as
    command line parser?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I recommend reading a book on unix or Linux shell and command line usage, in order to learn basic usage and get a feeling for some advanced features. Then you can turn to reference documentation.

The usage of specific commands is described in their manual. man cat will show the manual of the cat command on your system. Manual pages are usually references, not tutorials, though they often contain examples. On Linux, cat --help shows a terse usage message (meant for quick perusal when you already know the fundamentals and want to find an option for a specific task).

The POSIX standard specifies a minimum set of commands, options and shell features that every unix system is supposed to support. Most current systems by and large support POSIX:2004 (also known as Single UNIX version 3 and the Open Group Base Specifications issue 6). GNU software (the utilities found on Linux) often have many extensions to this minimum set.

There are common conventions for command-line arguments. POSIX specifies utility conventions that most utilities follow, in particular:

  • Options consist of - followed by a single letter; -ab is shorthand for -a -b.
  • -- signifies the end of options. For example, in rm -- -a, -a is not an option but an operand, i.e. a file to act upon, so this commands removes the file called -a.
  • A lone - stands for standard input, where an input file is expected. It stands for standard output where an output file is expected.

GNU utilities and others also support “long options” of the form --name. Some utilities go against the general convention and take multi-letter options with a single leading dash: -name.

Redirection is a shell feature, so you’ll find it in your shell’s manual. <<< to use a string as standard input is a ksh extension, also supported by bash and zsh. As long as the shell supports it, it can be used on any command.

Method 2

I would suggest looking into Unix in a Nutshell by O’rielly or merely just googling a bash tutorial.

Bash is aka Bourne Again SHell.

The other shells were SH, CSH, and KSH if I remember correctly. CSH is based on C.

I would also recommend learning C and Perl or Python, they help speed things up substantially.

Method 3

So is – meant to fill in an argument
supposed for filename?

Yes.

Is this usage
of – also common for other commands?

I’m not really sure if there is some standard for it, but some GNU tools (example: tar) use – for this purpose.

In cut -c 1-3,20,25- employees, is the
way 1-3,20,25- to specify a range of
numbers for an argument also common in
other commands?

It just seems to be natural. I’m sure you can use this in most of GNU tools – they are mostly following same conventions, but I’d check manual for any non-GNU tool.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x