One-liner Program Website Links For
Program
 

Information About

One-liner Program




In practice, one-liners will be entered and executed directly from the Command-line . As a consequence, one-liners are usually implemented with languages like BASIC , Bourne Shell , AWK , or Perl . Some Functional Programming languages also permit one-liners.


HISTORY


The word ''One-liner'' has two references in the index of the book The AWK Programming Language (the book is often referred to by the abbreviation ''TAPL''). It explains the programming language AWK , which is part of the Unix Operating System . The authors explain the birth of the ''One-liner'' paradigm with their daily work on early Unix machines:

Notice that this original definition of a ''One-liner'' implies immediate execution of the program without any compilation. So, in a strict sense, only source code for interpreted languages qualifies as a ''One-liner''. But this strict understanding of a ''One-liner'' was broadened in 1985 when the IOCCC introduced the category of ''Best One Liner'' for C , which is a compiled language.


EXAMPLES

The ''TAPL'' book contains 20 examples of ''One-liners'' ( A Handful of Useful awk One-Liners ) at the end of the book's first chapter.

Here are the very first of them:

  1. Print the total number of input lines:
    END { print NR }

  2. Print the tenth input line:
    NR == 10

  3. Print the last field of every input line:
    { print  }



Many one-liners are practical. For example, the following Perl one-liner will reverse all the bytes in a file:

perl -0777e 'print scalar reverse <>' filename

One-liners are also used to show off the differential expressive power of Programming Language s. Frequently, one-liners are used to demonstrate programming ability. Contests are often held to see who can create the most exceptional one-liner.

The following example is a C program (a winning entry in the "Best one-liner" category of the IOCCC .)