Pipelines

    A pipeline is composed of three parts: the input, the filter, and the output.

    The first command, , is an input (sometimes also called a “source” or “producer”). This creates or loads data and feeds it into a pipeline. It’s from input that pipelines have values to work with. Commands like ls are also inputs, as they take data from the filesystem and send it through the pipelines so that it can be used.

    The second command, inc package.version --minor, is a filter. Filters take the data they are given and often do something with it. They may change it (as with the command in our example), or they may do another operation, like logging, as the values pass through.

    The last command, save "Cargo_new.toml", is an output (sometimes called a “sink”). An output takes input from the pipeline and does some final operation on it. In our example, we save what comes through the pipeline to a file as the final step. Other types of output commands may take the values and view them for the user.

    The $in variable will collect the pipeline into a value for you, allowing you to access the whole stream as a parameter:

    Also see Subexpressions (opens new window)

    Nu commands communicate with each other using the Nu data types (see ), but what about commands outside of Nu? Let’s look at some examples of working with external commands:

    internal_command | external_command

    Data will flow from the internal_command to the external_command. This data will get converted to a string, so that they can be sent to the stdin of the external_command.

    external_command_1 | external_command_2

    Nu works with data piped between two external commands in the same way as other shells, like Bash would. The stdout of external_command_1 is connected to the stdin of external_command_2. This lets data flow naturally between the two commands.

    You may have wondered how we see a table if ls is an input and not an output. Nu adds this output for us automatically using another command called . The table command is appended to any pipeline that doesn’t have an output. This allows us to see the result.

    In effect, the command:

    And the pipeline: