zsh-workers
 help / color / mirror / code / Atom feed
* Strange behaviour in zsh-2.5.03
@ 1995-12-11  8:44 Sverre Slotte
  1995-12-11  9:08 ` Bas V. de Bakker
  1995-12-11  9:52 ` P.Stephenson
  0 siblings, 2 replies; 3+ messages in thread
From: Sverre Slotte @ 1995-12-11  8:44 UTC (permalink / raw)
  To: zsh-workers

Hi,

I'm running zsh version 2.5.03 on a Sun SparcStation 4 w/ Solaris 2.4.

I have a shell function called "lpr" that acts as a front-end to
/usr/ucb/lpr. It lets me specify the printer I want in a "localised"
fashion: -Pf and -Pc stand for fax-room printer and coffee-room
printer, respectively. Unfortunately, it fails in a mysterious manner.

The function looks like this:

    function lpr()
    {
        local printer=${PRINTER:-your_default_printer}
        local passthru=
    
        while [[ $# -gt 0 ]]
        do
            case "$1" in
                -Pc | -PC | -Pps3ac )
                    printer=ps3ac           # c for coffee-room
                    ;;
                -Pf | -PF | -Pps3d )
                    printer=ps3d            # f for fax-room
                    ;;
                -P )
                    $[2]=$1$2               # turn -P prn into -Pprn
                    ;;
                * )
                    passthru="$passthru $1"
                    ;;
            esac
            shift
        done
    
        command lpr -P${printer} ${passthru}    # this doesn't work!
    }

(Comments on shell-programming style welcome.)

The last line is the one that fails: if I try to print a file (e.g
lpr -Pc foobar.ps) I get the response "lpr: cannot access foobar.ps".

However, if I prepend the whole line with an echo, I get the expected
result on stdout: "command lpr -Pps3ac foobar.ps". And if I replace
the echo with eval, turning the line into

    eval command lpr -P${printer} ${passthru}

everything works fine: no complaints at all and foobar.ps appears on
the printer.

Any explanation for this? Is is a bug? Is it already fixed in
2.6.whatever?

Cheers,

Sverre

----------------------------------------------------------------------------
Sverre Slotte                            Internet: sverre@research.nokia.com
Nokia Research Center                    Phone:             + 358 0 43766208
P.O.Box 45, 00211 Helsingfors, Finland   Phax:              + 358 0 43766856
----------------------------------------------------------------------------
"Kajakken er uten sammenligning den ypperste enkeltmannsfarkost som finnes."
                                                      -- Fritjof Nansen 1891



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Strange behaviour in zsh-2.5.03
  1995-12-11  8:44 Strange behaviour in zsh-2.5.03 Sverre Slotte
@ 1995-12-11  9:08 ` Bas V. de Bakker
  1995-12-11  9:52 ` P.Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: Bas V. de Bakker @ 1995-12-11  9:08 UTC (permalink / raw)
  To: sverre; +Cc: zsh-workers

Sverre Slotte <sverre@research.nokia.com> writes:

>                     passthru="$passthru $1"
                                         ^
It's this space that gets in the way.  The passthru variable will
consist of the filename with a space added to the end, which makes a
new filename that does not exist.  Similarly, if you have more files,
they will all become a single argument in the following command, being
interpreted as a single file name.

>         command lpr -P${printer} ${passthru}    # this doesn't work!

As long as you don't have filenames which themselves contain
whitespace, replacing ${passthru} with ${=passthru} should do the job,
as this will split the variable into different words.

Hope this helps.

Bas.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Strange behaviour in zsh-2.5.03
  1995-12-11  8:44 Strange behaviour in zsh-2.5.03 Sverre Slotte
  1995-12-11  9:08 ` Bas V. de Bakker
@ 1995-12-11  9:52 ` P.Stephenson
  1 sibling, 0 replies; 3+ messages in thread
From: P.Stephenson @ 1995-12-11  9:52 UTC (permalink / raw)
  To: Sverre Slotte; +Cc: Zsh hackers list

sverre@research.nokia.com wrote:
> Hi,
> 
> I'm running zsh version 2.5.03 on a Sun SparcStation 4 w/ Solaris 2.4.
> 
> I have a shell function called "lpr" that acts as a front-end to
> /usr/ucb/lpr. It lets me specify the printer I want in a "localised"
> fashion: -Pf and -Pc stand for fax-room printer and coffee-room
> printer, respectively. Unfortunately, it fails in a mysterious manner.

Here's the problem...

>                 * )
>                     passthru="$passthru $1"

...

>         command lpr -P${printer} ${passthru}    # this doesn't work!

it's shell word splitting.  You're trying to print " foo.ps".  Use
${=passthru} and everything should be OK.  Even better, make passthru
an array: that's what they're there for:

passthru=($passthru $1)

or if it has to work with ksh too,

set -A passthru $passthru $1

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1995-12-11 10:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-12-11  8:44 Strange behaviour in zsh-2.5.03 Sverre Slotte
1995-12-11  9:08 ` Bas V. de Bakker
1995-12-11  9:52 ` P.Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).