CHAPTER 27Read Piped Input

Many programs available to the UNIX or Linux operating systems have the ability to process input from standard input through a pipe, Similarly, the following short script demonstrates how to perform this task using a shell script. The script also demonstrates a number of interesting techniques that are covered in more depth elsewhere in this book.

The purpose of the script is to take its input, whether from a file or stdin, and print the data to stdout in reverse order. The script provides two ways to perform this task. The first method works by calling the script with an argument that is the name of the file to be reversed. Alternatively, you can pipe output from some other command into the script, and it will then ...

Get Expert Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.