100% Spam Free Email | Contact Us | Products/Services | Korn Shell | MicroEMACS


Mt Xia:
Technical Consulting Group

 

tee_k93


Contact Mt Xia for help with your shell scripting projects at 615.556.0456 or dfrench@mtxia.com

Current:tee_k93
Previous:
Home Page



#!/usr/bin/ksh93
################################################################
#### Program: tee_k93
#### 
#### Description: Emulation of the Unix "tee" command
#### 
#### Author: Dana French (dfrench@mtxia.com)
####         Copyright 2004
#### 
#### Date: 07/28/2004
#### 
################################################################
function tee_k93 {
  typeset TRUE="0"
  typeset FALSE="1"
  typeset VERBOSE="${FALSE}"
  typeset VERYVERB="${FALSE}"
  typeset APPEND="${FALSE}"
  typeset FNAME

  while getopts ":avV" OPTION
  do
    case "${OPTION}" in
        'a') APPEND="${TRUE}";;
        'v') VERBOSE="${TRUE}";;
        'V') VERYVERB="${TRUE}";;
        '?') print "Syntax: tee_k93 [FILE]..." && exit 1 ;;
    esac
  done
 
    shift $(( ${OPTIND} - 1 ))

    FNAME="${1}"
    if [[ "_${FNAME}" = "_" ]]
    then
        print -u 2 "ERROR: output file name not specified"
        return 1
    fi
    if (( APPEND == TRUE ))
    then
        if ! exec 3>>"${FNAME}"
        then
            print -u 2 "ERROR: Unable to append to file ${FNAME}"
            return 2
        fi
    else
        if ! exec 3>"${FNAME}"
        then
            print -u 2 "ERROR: Unable to write to file ${FNAME}"
            return 3
        fi
    fi

    while IFS="" read -r -- LINE
    do
        print -u 3 -r -- "${LINE}"
        print -r -- "${LINE}"
    done

    exec 3>&-

  return "${TRUE}"
}
################################################################

tee_k93 "${@}"

 

For information regarding this page, contact Dana French ( dfrench@mtxia.com )
Copyright 2008 by Mt Xia Inc, All Rights Reserved