2

I have been looking for lesser known commands that reads their standard input in special cases(missing arguments , for example).

I'm thinking "cat" or maybe other command would fit here.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
hbrtxito
  • 25
  • 3
  • I think you're going to need to define "special cases". The cat command will read from stdin either when there are no arguments or when it encounters - in the list of files to process. Neither seems a particularly special case to me. – Chris Davies Oct 24 '15 at 11:59
  • Maybe a "special case": htpasswd without option -b will prompt for the password (it is the standard way for security reasons). – hellcode Oct 24 '15 at 12:06
  • Many unix/linux commands read from stdin when they aren't given filenames to process (or when the filename is -or, at worst, /dev/stdin). It's perfectly normal and not in the least bit unusual or "special case". There has been an unfortunate trend in recent years to write tools that are incapable of this (looking at YOU, python programmers) but they're still rare. – cas Oct 24 '15 at 12:26
  • in short, if it seems like it would make sense or be useful for a unix tool to read from stdin, then it probably does. if it doesn't, file a bug report :) – cas Oct 24 '15 at 12:27
  • Thanks for the comments guys , the question was totally unclear to me too. I appreciate your time for answering my question. – hbrtxito Oct 24 '15 at 16:23

1 Answers1

3

There are a few cases that come to mind:

  • missing arguments,
  • the special argument "-",
  • the program detects that the standard input is not a terminal, and
  • an option (or environment variable) overrides the behavior.

For missing arguments, cat is a useful example. Likewise grep, sed.

The special argument "-" is used in several programs to tell it explicitly to read from the standard input. You can find discussion (with examples) in these:

For the case where the standard input is not a terminal—offhand, the cases I'm familiar with are less known:

  • dialog checks on startup if its input is a terminal, and if not, opens the terminal device. This is part of a larger scheme where it can read data from a pipe, e.g., for the gauge widget.
  • diffstat handles missing arguments by reading its input from the standard input, but in addition, its -v (verbose) option when doing this shows progress, e.g., a "." for each file
  • piping to vi-like-emacs makes it read the input as a file. vim's comparable feature (implemented [later4), uses the explicit "-" argument.

For special arguments:

  • dialog has an option --gauge which reads data from the standard input. Also --input-fd tells it which file descriptor to use as its input for pipes.
  • lynx has an option -stdin telling it to interpret the standard input as html. Otherwise, it accepts configuration options on the standard input, e.g., using -get_data or -post_data.
Thomas Dickey
  • 76,765