Imported from ../bash-2.0.tar.gz.
[platform/upstream/bash.git] / examples / scripts.noah / shcat.bash
1 # shcat.bash
2 # Author: Noah Friedman <friedman@prep.ai.mit.edu>
3 # Created: 1992-07-17
4 # Last modified: 1993-09-29
5 # Public domain
6
7 # Conversion to bash v2 syntax done by Chet Ramey
8
9 # Commentary:
10 # Code:
11
12 #:docstring shcat:
13 # Usage: shcat {file1} {file2} {...}
14 #
15 # Like `cat', only this is all inline bash. 
16 #:end docstring:
17
18 ###;;;autoload
19 function shcat ()
20 {
21  local IFS=""
22  local line
23  local file
24  local exitstat=0
25  
26     if [ $# -eq 0 ]; then
27        while read -r line; do
28           echo "${line}"
29        done
30        return 0
31     else
32        for file in "$@" ; do
33           if [ -r "${file}" ]; then
34                while read -r line; do
35                   echo "${line}"
36                done < "${file}"
37           else
38              # This will cause the error to be printed on stderr
39              < "${file}"
40              exitstat=1
41           fi
42        done
43        return ${exitstat}
44     fi
45 }
46
47 provide shcat
48
49 # shcat.bash ends here