home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d811 / bsh.lha / bsh / head < prev    next >
Text File  |  1993-02-14  |  892b  |  45 lines

  1. local i l j n f IFS k
  2. onerr goto err
  3. onintr goto err
  4. n=#argv,IFS="\n"
  5. j=1-(n<2),f=0,k=10
  6. while j<n
  7.    if left(argv[j], 1) == '-' && numeric(argv[j])
  8.     if argv[j] < 0
  9.         k = -argv[j]
  10.     endif
  11.     j++
  12.     continue
  13.    endif
  14.    if j>0
  15.     if (f=open(argv[j],"r")) == 0
  16.        j++
  17.        continue
  18.     endif
  19.     read l <&$f
  20.     if eof(f)
  21.        goto empty
  22.     endif
  23.     echo "==> $argv[$j] <=="
  24.     echo $l
  25.     i=1
  26.    else
  27.     f=i=0
  28.    endif
  29.    while i++<k;read l <&$f;if eof(f);break;endif;echo $l;endwhile
  30.    label empty
  31.    close $f
  32.    f=0,j++
  33. endwhile
  34. label err
  35. if f
  36.    close $f
  37. endif
  38. # head - print the first few lines of a file/files.  The innermost while
  39. # is compressed to one line for performance.
  40. #
  41. # Head is presented as is; no warrantee is either expressed or implied
  42. # as to it's suitability to any purpose whatsoever.  You assume all the
  43. # risk for all damage, even if caused by a defect in the software,
  44. # no matter how awful.
  45.