tsort - topological sort
The tsort utility writes to standard output a totally ordered list of items consistent with a partial ordering of items contained in the input.
The input consists of pairs of items (non-empty strings) separated by blanks. Pairs of different items indicate ordering. Pairs of identical items indicate presence, but not ordering.
The following operand is supported:
- A pathname of a text file to order. If no file operand is given, the standard input is used.
The standard input is a text file that is used if no file operand is given.
The input file named by the file operand is a text file.
The following environment variables affect the execution of tsort:
- Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
- If set to a non-empty string value, override the values of all the other internationalisation variables.
- Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files).
- Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
- Determine the location of message catalogues for the processing of LC_MESSAGES .
The standard output is a text file consisting of the order list produced from the partially ordered input.
Used only for diagnostic messages.
The following exit values are returned:
- Successful completion.
- An error occurred.
The LC_COLLATE variable need not affect the actions of tsort. The output ordering is not lexicographic, but depends on the pairs of items given as input.
tsort <<EOF a b c c d e g g f g e f h h EOF
produces the output:
a b c d e f g h