Pipelines let one tool feed another. This example compares a unique sorted list with a reverse sorted list.

Program

Play the script to choose the pipeline mode and see the modeled output.

sort_unique_plan.sh
#!/usr/bin/env bash

mode=
input="beta alpha alpha"
if [ "$mode" = "unique" ]; then
    command="sort | uniq"
    output="alpha beta"
else
    command="sort -r"
    output="beta alpha alpha"
fi
echo "$command -> $output"
#!/usr/bin/env bash

mode=
input="beta alpha alpha"
if [ "$mode" = "unique" ]; then
    command="sort | uniq"
    output="alpha beta"
else
    command="sort -r"
    output="beta alpha alpha"
fi
echo "$command -> $output"
pipeline A pipeline connects commands so each stage transforms the stream.
sort `sort` orders lines before later processing.
uniq `uniq` removes adjacent duplicate lines after sorting.