euglug.org

[Eug-lug] Reading data to multiple variables

작성자

카테고리:



Bob MillerThu Jul 29 09:56:10 PDT 2004

Garl Grigsby wrote:

>    I owe you a beer.

You're welcome.

> The way you had it the read would stop just after the Protocol line. It 
> would never process the Transport, GUID, or the Attached lines. Again, I 
> have no idea why this is happening. I can't find anything in there that 
> would cause it to fail but it did. Any way, this works, and works well.

Files in /proc aren't real files, so they probably don't support being
read line-by-line.  I didn't have any USB storage devices handy to
test against, so I didn't notice.  Sorry.

If you're planning to deploy this where security matters, I suggest
you use a secure temp file name:

	tmp=`mktemp`
	cat "$unit" > "$tmp"
	while ...
	done < "$tmp"
	rm "$tmp"		# cleanliness is next to

Or you might be able to read by lines by buffering the input with cat.

	cat "$unit" | while read name value
		      do ...
		      done

-- 
Bob Miller                              K<bob>
kbobsoft software consulting
http://kbobsoft.com                     kbob at jogger-egg.com