home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Unix Power ToolsUnix Power ToolsSearch this book

36.17. 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 stdin-demo script:

while read word
   echo $word | sed s/foo/bar/

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

-- CT

Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.