LinuxCommandLibrary

line

Read one line from standard input

TLDR

Read input

$ line
copy

SYNOPSIS

line

DESCRIPTION

The line command is a very simple Linux utility that reads a single line of text from its standard input and writes it to its standard output. It processes input until a newline character is encountered, outputs the collected line (typically stripping the newline), and then exits. Historically, line served as a basic mechanism for scripts to acquire a single line of dynamic input, especially in environments where more advanced shell built-ins like read were not as prevalent or standardized.

It has no options or arguments, making its functionality extremely focused. Due to its simplicity and the widespread availability of more versatile shell built-ins, line is often considered obsolete for modern scripting, but it remains available for backward compatibility with older Unix scripts.

CAVEATS

  • Lack of Options: line provides no options for controlling its behavior, such as specifying a delimiter, timeout, or prompt.
  • Obsoleteness: For most modern scripting tasks, the read built-in command (available in bash, zsh, ksh, etc.) is a much more versatile and efficient alternative, offering features like prompting, timeouts, specifying delimiters, and handling backslashes.
  • Single Line Only: It only reads and outputs one line, then exits, making it unsuitable for processing multi-line input streams directly.
  • Blocking Behavior: It will block indefinitely if no input is provided to standard input.

USAGE IN PIPELINES

While simple, line can still be used effectively in pipelines when only the very first line of a stream needs to be processed. For example, command | line | another_command would pass only the first line of command's output to another_command, discarding subsequent lines from the initial stream.

COMPARISON WITH 'READ'

Unlike the read built-in, line does not directly handle input into shell variables. It simply passes the line to standard output. This makes it less flexible for parsing input within a script where variable assignment is key, but potentially simpler for basic pipe-based operations where only the first line is needed and subsequent processing happens externally.

HISTORY

The line command is an ancient Unix utility, tracing its roots back to very early versions of Unix, appearing as early as Unix Seventh Edition (V7) in 1979. Its design reflects the constraints and practices of early shell scripting environments, where sophisticated built-ins were less common or standardized. Over time, as shell built-ins like read matured and became widely available across different shells, the direct utility of line diminished significantly. Today, it's largely maintained for backward compatibility with very old scripts, rather than for active new development, and is typically part of core utility packages like util-linux on Linux systems.

SEE ALSO

read(1), echo(1), cat(1), head(1)

Copied to clipboard