Maybe I'm missing the point of the original post, but it says "Display file contents ...". If what you want to display is already a file, why copy the contents of the file to a temporary file (especially using awk to do the copy), just to run wc on it, and either cat or less on it? This works just as well, and you don't have to redirect stdin:<br>
out() { if [ $(wc -l $1 | awk '{print $1}') -gt $(tput lines) ]; then less $1; else cat $1; fi; }<br><br>If what's desired is run cat or less on the output of some command, then this command covers both files and pipes:<br>
<br>out() { if [ $# -gt 0 ];then tmp=$*; else tmp=$(mktemp /tmp/XXXXXX); cat >|$tmp; fi; if [ $(wc -l $tmp | awk '{print $1}') -gt $(tput lines) ]; then less $tmp; else cat $tmp; fi; if [ $# -eq 0 ];then rm -fr $tmp; fi; }<br>
<br>Then both of these will work:<br>$ out foo.txt<br>$ grep 'some string' foo.txt | out<br><br>I added a template to the mktemp command because some older linuxes expect a template. I also added a '|' on the redirect because I have my bash set such that it won't overwrite an existing file on redirect (which is really handy if you meant to type "<foo.txt" but instead typed ">foo.txt").<br>
<br><br><div class="gmail_quote">On Tue, Oct 25, 2011 at 9:30 AM, Paul Gray <span dir="ltr"><<a href="mailto:gray@cs.uni.edu">gray@cs.uni.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 10/25/2011 09:21 AM, Scott Prader wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Could probably write a wrapper for cat (maybe call it dog) and have it<br>
reference /etc/mine.types and/or the file command so that once it<br>
understands the 'scent' of the file, it will know how to process the<br>
file based off of the preferred application for it. For instance, if<br>
you ran the command:<br>
<br>
dog kitty.jpg<br>
<br>
, it should know to figure out that it's an image file (file kitty.jpg),<br>
check the environment (is ${DISPLAY} set?), figure out which application<br>
to use (cross reference with mime.types depending on the environment),<br>
and run the appropriate command to display the image.<br>
</blockquote>
<br></div>
On a Mac, isn't this just the "open" command?<br><font color="#888888">
<br>
-- <br>
Paul Gray -o)<br>
314 East Gym, Dept. of Computer Science /\\<br>
University of Northern Iowa _\_V<br>
Message void if penguin violated ... Don't mess with the penguin<br>
No one says, "Hey, I can't read that ASCII attachment ya sent me."</font><div><div></div><div class="h5"><br>
______________________________<u></u>_________________<br>
Cialug mailing list<br>
<a href="mailto:Cialug@cialug.org" target="_blank">Cialug@cialug.org</a><br>
<a href="http://cialug.org/mailman/listinfo/cialug" target="_blank">http://cialug.org/mailman/<u></u>listinfo/cialug</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Tim<br>Required reading: <a href="http://bccplease.com/">http://bccplease.com/</a><br>