[Chapter 45] 45.24 A Shell Can Read a Script from its Standard Input, But...
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:54:55Z

#

| Chapter 45 Shell Programming for the Initiated |

## 45.24 A Shell Can Read a Script from its Standard Input, But...

Q: What is the difference between `sh < file` and `sh file`?

A: The first way keeps the script from reading anything else from its input. Consider the zip script:

A:

>     while read word
>     do   echo $word | sed s/foo/bar/
>     done

If run as `sh zip`, it will read from your terminal, replacing `foo` with `bar`. If run as `sh < zip`, it will exit right away, since after reading the script, there's no input left.

- CT in net.unix on Usenet, 29 December 1984

45.23 The Ins and Outs of Redirected I/O Loops |  | 45.25 Shell Scripts On-the-Fly from Standard Input