Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Opening a file for READing within script? (Last question today ;) )




On Dec 10, 2008, at 12:34 PM, Webb Sprague wrote:

I want to open a file given at the command line for reading by
associating it with a file descriptor number and then running

read -u 4 HEADERLINE
echo "Special header line behavior $HEADERLINE"

while read -u 4 DATALINE ; do
   echo $DATALINE
   sleep 1
done

I am doing this because I need to process the header differently than
the data, and I want the user to give the file name on the command
line rather than cat it into a pipeline.

Thanks!

(Oh -- my final FINAL sneaky question -- is there a way to
automagically associate the OPTS with an associative array?  like

optfill f:b OPTASSOC

modifying OPTASSOC to be {f->filename; b->EMPTY}, given command -b -f
filename; it would throw an error for required or non-standard opts
too, but not sure about good syntax ?  If there isn't, I will write
one, but not today ....
)

Not sure about your first question but as for your final sneaky question...

given options (via a function call or call to your script, etc), the line

zparseopts -D -E -A opts f: b:

when inside your function,

will take the positional parameters and add the options f and b to the associative array named opts so that:

call_my_function -f FVAL -b BVAL

$opts[-f] will be equal to FVAL
$opts[-b] will be equal to BVAL

check out man zshmodules and look for zparseopts in there for the details on that

--Mike H



Messages sorted by: Reverse Date, Date, Thread, Author