The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 06-04-2008
robotball robotball is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 8
Question Passing a file descriptor

I am trying to right a function which uses a file descriptor to write to a log file. The problem is that the on the print statement the file descriptor is called bad. Now when I first open the file and print to it in the f_open function by passing the descriptor to f_print_log all works well, however when I returned the file descriptor to logtest.sh and then try to pass it to f_print_log I get bad file descriptor. Any help would be appreciated. Here are my functions and calling script:

********* THESE FUNCTIONS ARE IN f_log.sh
function f_open_log
{
next_fh=$LOG_FH_COUNTER
eval "exec $next_fh>$1"

f_print_log $next_fh "Log file opened"
(( LOG_FH_COUNTER=LOG_FH_COUNTER + 1 ))

echo ${next_fh}
return 0
}

function f_print_log
{
print -u$1 $2
return 0
}
***************************************************

logtest.sh -->

#!/bin/ksh

. f_log.sh

typeset -i LOG_FH_COUNTER=3

LOG=$(f_open_log bigfile)
f_print_log $LOG "This is a test"

exit