With what we've learned so far, it's easy to combine the output of two separate commands into a file; we just run them in the appropriate sequence, and use the redirection output with >> to append the data:
$ date > myout $ hostname >> myout $ cat myout Mon Jul 30 21:32:33 NZST 2018 bashserver.example.net.
However, it may not be clear how you could combine two streams of output from commands into one without saving them into a temporary file, for example to capitalize all of the letters within it with tr. There isn't a specific syntax to "merge" pipes.
There is still a way to do this without resorting to a temporary file; you can use a compound command that contains all of the commands for output redirection, and apply the redirection to that compound command, rather than to the individual commands within it.
The most straightforward way to do this is with a group command, which is delimited with curly brackets, { and }:
$ { date ; hostname ; } | tr a-z A-Z MON JUL 30 21:38:52 NZST 2018 BASHSERVER.EXAMPLE.NET.
Note that we not only had to separate the date and hostname commands here with a semicolon, we also had to include a semicolon control operator for the final command to terminate it, before closing the group with }. This form of compound command is the same as the one commonly used for functions, as we'll see in Chapter 7, Scripts, Functions, and Aliases.
Input and output redirection can also apply to compound commands:
$ { date ; printf '%s\n' apple carrot banana ; } > mywords $ { read date ; printf '%s\n' "$date" ; sort ; } < mywords
There are other kinds of compound commands, which we'll learn about in Chapter 6, Loops and Conditionals, for which redirection works just as well. This property of redirection for compound commands is the basis of Bash's while read -r loop idiom, for reading a file line-by-line.