[gnu.bash.bug] Bug report: quoted strings passed to functions

night@pawl.rpi.edu (Trip Martin) (11/13/89)

Configuration: bash 1.04.1, SysVR3.1, ATT 3B2/300

bash$ grep() { egrep $* ; }
bash$ grep 'foo bar' testfile
egrep: bar does not exist

-- 
Trip Martin  KA2LIV       night@pawl.rpi.edu
Finite state machinist    night@uruguay.acm.rpi.edu

dce@sony.com (David Elliott) (11/14/89)

In article <1989Nov13.054213.24296@rpi.edu> night@pawl11.pawl.rpi.edu (Trip Martin) writes:
>Configuration: bash 1.04.1, SysVR3.1, ATT 3B2/300
>
>bash$ grep() { egrep $* ; }
>bash$ grep 'foo bar' testfile
>egrep: bar does not exist

The bug is in the use of $*, not bash.  This is a common problem, caused
by a flaw in the design of the original sh.

Change that to

	grep() { egrep "$@" ; }

and it will work as expected.

Hey, Brian, maybe you could add a special mode to bash that would
print out warnings for all uses of $* and unquoted variable
references, or maybe someone could write "shlint". ;-)
-- 
David Elliott
dce@sony.com | ...!{uunet,mips}!sonyusa!dce
(408)944-4073
"You can lead a robot to water, but you can not make him compute."

night@pawl.rpi.edu (Trip Martin) (11/18/89)

In <1989Nov13.162429.12744@sony.com> dce@icky.Sony.COM (David Elliott) writes:
>The bug is in the use of $*, not bash.  This is a common problem, caused
>by a flaw in the design of the original sh.
>
>Change that to
>
>	grep() { egrep "$@" ; }
>
>and it will work as expected.

It doesn't work as expected.  When I tried it, egrep waited for input
from stdin.  

-- 
Trip Martin  KA2LIV       night@pawl.rpi.edu
Finite state machinist    night@uruguay.acm.rpi.edu
-- 
--russ (nelson@clutx [.bitnet | .clarkson.edu])
Live up to the light thou hast, and more will be granted thee.
A recession now appears more than 2 years away -- John D. Mathon, 4 Oct 1989.
I think killing is value-neutral in and of itself. -- Gary Strand, 8 Nov 1989.

dce@sony.com (David Elliott) (11/19/89)

In article <1989Nov13.233322.15607@rpi.edu> night@pawl.rpi.edu (Trip Martin) writes:
>In <1989Nov13.162429.12744@sony.com> dce@icky.Sony.COM (David Elliott) writes:
>>	grep() { egrep "$@" ; }

>It doesn't work as expected.  When I tried it, egrep waited for input
>from stdin.  

Exactly.

Sorry.  The problem is that there seems to be another bug in
bash, in which "$@" is treated incorrectly.  I apologize for
not testing my example carefully when I posted.  This bug was
discovered a couple of days later.

Sadly, without "$@" working correctly, I don't know of a simple
way to do what you want (does bash have aliases?).
-- 
David Elliott
dce@sony.com | ...!{uunet,mips}!sonyusa!dce
(408)944-4073
"You can lead a robot to water, but you can not make him compute."