Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function usage() {
- cat <<__EOT__
- Usage:
- $0 [-f filename]
- Example:
- cat file1 | $0
- $0 < file1
- $0 -f file1
- __EOT__
- exit 1
- }
- if [ -p /dev/stdin ] || [ -f /dev/stdin ]; then
- d=$(cat /dev/stdin)
- else
- while getopts f: OPT
- do
- case $OPT in
- f) FILENAME=$OPTARG
- ;;
- \?) usage
- ;;
- esac
- done
- if [ -z $FILENAME ]; then
- usage
- exit 1
- fi
- if [ -f $FILENAME ]; then
- d=$(cat $FILENAME)
- else
- echo "Not found $FILENAME"
- usage
- exit 1
- fi
- fi
- echo "$d"
Add Comment
Please, Sign In to add comment