Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Strange behaviour in zsh-2.5.03



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@xxxxxxxxxxxxxxxxxx
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




Messages sorted by: Reverse Date, Date, Thread, Author