*BSD News Article 95873


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.mel.connect.com.au!munnari.OZ.AU!news.ecn.uoknor.edu!feed1.news.erols.com!howland.erols.net!math.ohio-state.edu!jussieu.fr!oleane!weld.news.pipex.net!pipex!warm.news.pipex.net!pipex!tank.news.pipex.net!pipex!news.utell.co.uk!usenet
From: brian@shift.utell.net (Brian Somers)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Printing with FreeBSD 2.1.6
Date: 21 May 1997 10:29:57 GMT
Organization: Awfulhak Ltd.
Lines: 75
Message-ID: <5luir5$39p@ui-gate.utell.co.uk>
References: <33821625.1F2210DB@cyberworld.demon.co.uk>
Reply-To: brian@awfulhak.org, brian@utell.co.uk
NNTP-Posting-Host: shift.utell.net
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Newsreader: knews 0.9.8
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:41348

In article <33821625.1F2210DB@cyberworld.demon.co.uk>,
	Lee Johnston <ljohnston@cyberworld.demon.co.uk> writes:
> I am using FreeBSD 2.1.6 with a non postscript printer (a Canon BJC-4100
> Bubble Jet simulating a Epson LQ). I have managed to get ghostscript to
> printout a .ps file on the printer, but when I create a printer filter
> that is included in the FreeBSD handbook, which is shown below, it
> doesn't work!
> 
> #!/bin/sh
> #
> #  ifhp - Print Ghostscript-simulated PostScript on a Canon BJC-4100
> #  Installed in /usr/local/libexec/hpif
> #
> #  Treat LF as CR+LF:
> #
> printf "\033&k2G" || exit 2
> #
> #  Read first two characters of the file
> #
> read first_line
> first_two_chars=`expr "$first_line" : '\(..\)'`
> if [ "$first_two_chars" = "%!" ]; then
>     #
>     #  It is PostScript; use Ghostscript to scan-convert and print it
>     #
>     /usr/local/bin/gs -dSAFER -dNOPAUSE -q -sDEVICE=epsonc
> -sOutputFile=- - \
>         && exit 0
> else
>     #
>     #  Plain text or HP/PCL, so just print it directly; print a form
>     #  at the end to eject the last page.
>     #
>     echo $first_line && cat && printf "\f" && exit 2
> fi
> exit 2
> 
> I suspect that it may be the line ' first_two_chars=`expr "$first_line"
>: '\(..\)'` ' as when I try a simple filter shown below, to echo the
> result of the ' first_two_chars=`expr "$first_line" : '\(..\)'` ' line
> to the printer, if only prints out ' expr "$first_line" : '\(..\)' '.
> 
> #!/bin/sh
> read first_line
> first_two_chars=`expr "$first_line" : '\(..\)'`
> echo $first_two_chars && exit 0
> exit 2
> 
> Has anyone come across this problem, and how do I solve it, Thanks!

This works ok for me:
shift:/tmp $ cat xxx
#!/bin/sh
read first_line
first_two_chars=`expr "$first_line" : '\(..\)'`
echo $first_two_chars && exit 0
exit 2
shift:/tmp $ echo hello | ./xxx
he
shift:/tmp $ 

Are you sure your quotes are the correct ones ?  I find it clearer
to use the $(command) syntax rather than the `command` syntax.


> ______
> Lee Johnston
> ljohnston@cyberworld.demon.co.uk
> http://www.cyberworld.demon.co.uk
> 

-- 
Brian <brian@awfulhak.org> <brian@freebsd.org>
      <http://www.awfulhak.org>
Don't _EVER_ lose your sense of humour !