🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.sys5
Article #51

Re: ksh bugs

#51
From: Warren D. Swan
Date: Tue, 08 Aug 1989 18:58
48 lines
2455 bytes
In article <10166@fluke.COM> foot@tc.fluke.COM (Andrew Proudfoot) writes:
>2. the "read" command does filename expansion on its input! 
>   Just filename expansion; it doesn't do quote removal or tilde expansion.
>   This happens only on the Suns, not on the Vaxes.
>
>    $ ls /usr0/foot/xx
>    file1   file2   file3
>    $ ls ~foot/xx
>    file1   file2   file3
>    $ while read stuff; do echo $stuff; done << EOF
>    > ~foot/xx/*
>    > '/usr0/foot/xx/*'
>    > /usr0/foot/xx/*
>    > EOF
>    ~foot/xx/*
>    '/usr0/foot/xx/*'
>    /usr0/foot/xx/file1 /usr0/foot/xx/file2 /usr0/foot/xx/file3

The other two sound like problems, but this one definitely isn't.  This is
not the read statement doing filename expansion.  Nor is it, as someone
ludicrously suggested without checking, the here document doing filename
expansions, because the shell only does $ expansion on here documents
[unless the sentinel (EOF) is quoted, even partially ('EOF' or \EOF)], NOT
` or filename expansions.

The problem is in your reference to $stuff.  One of the first rules of shell
programming ought to be:  Always quote any expansion of an environment or
shell variable (unless you WANT something like the above to happen).

Just change your while loop to read:
$ while read stuff; do echo "$stuff"; done <<EOF
...

You see, the shell does filename expansion AFTER doing $ expansion.  So
$stuff is being replaced with /usr0/foot/xx/*, which is then expanded by
the shell, and the individual arguments are then handed to echo.

Try this:
JUNK='*'  # (I use quotes to delay another long discussion here, but they're
          # not needed.  JUNK=* would do the same thing.)
echo $JUNK  # "Weeeee. Lookah my files."
echo "$JUNK"  # "What a pretty little star!"

Have fun,
Warren D. Swan  (WooDS)     Y n n ____ __      You can't tell which way a train
AT&T Bell Laboratories     -(((((([__]/__]     went by looking at the tracks.
Naperville, Illinois       /o-OOOOO~~  oo
att!cblph!woods         #####################  FRISCO 1630 Decapod (2-10-0) IRM
Technical Details
Message-ID: <2316@cbnewsc.ATT.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!att!cbnewsc!woods
References: <10166@fluke.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!att!cbnewsc!woods
From: woods@cbnewsc.ATT.COM (Warren D. Swan)
Newsgroups: comp.bugs.sys5
Subject: Re: ksh bugs
Keywords: ksh
Message-ID: <2316@cbnewsc.ATT.COM>
Date: 8 Aug 89 18:58:21 GMT
References: <10166@fluke.COM>
Reply-To: woods@cblph.ATT.COM (Warren D. Swan)
Distribution: na
Organization: AT&T Bell Laboratories
Lines: 48