[comp.unix.wizards] shell globbing universal ?????

matt@oddjob.UChicago.EDU (Java Man) (12/04/87)

Yesterday I read here how groovy it is that wildcard expansion is
done by the shell, so the semantics are the same for every command.

Today:

o 203% ls
gnuemacs.tar	patch.tar.Z
o 204% dd if=g*
No match.
o 205% set if=g*
o 206% echo $if
gnuemacs.tar

(SunOS 3.4 csh, but I'm sure they're all the same ...)

			Matt Crawford

gwyn@brl-smoke.UUCP (12/05/87)

In article <14107@oddjob.UChicago.EDU> matt@oddjob.uchicago.edu (Java Man) writes:
>o 204% dd if=g*
>o 205% set if=g*

Both of these, the "dd" utility and the Cshell's brain-damaged "set"
syntax, exhibit irregularities.

"dd" is one of the few commands that was deliberately designed to have
a stupid IBMish syntax rather than fit the general UNIX command model.
There was no filename starting "if=g" so the glob failed.  "dd" fits
the model of a command that insists on doing its own parsing instead
of letting the shell take care of it, and it happens to have no builtin
globbing. It should have been designed to accept file arguments like
	dd -i in_file -o out_file
which would fit the generally accepted shell interface.

The Cshell "set" built-in uses the "=" as a delimiter, so it treated
the stuff to the right of the "=" as through it had been preceded by
a space under normal argument handling, and was able to glob it.  If
the Cshell builtin had been designed to be invoked like
	setvar if g*
it would have made more sense.

All this shows is that "dd" ought to be fixed and the Cshell should
be stamped out..

stpeters@dawn.steinmetz (Dick St.Peters) (12/05/87)

In article <6793@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <14107@oddjob.UChicago.EDU> matt@oddjob.uchicago.edu (Java Man) writes:
>>o 204% dd if=g*
>>o 205% set if=g*
	[deleted]
>All this shows is that "dd" ought to be fixed and the Cshell should
>be stamped out..

Hell, no!  "Fixing" dd would break an awful lot of scripts, and it's
shell chauvinism that ought to be stamped out.  Flexibility of the user
interface, including a choice of shells (and the freedom to write your
own if you want) is part of what makes UNIX great.  I may not agree
with your choice of shells, but I will defend your right to use it.

(For those unfamiliar with csh, "set if = g*" works just fine.)
--
Dick St.Peters                        
GE Corporate R&D, Schenectady, NY
stpeters@ge-crd.arpa              
uunet!steinmetz!stpeters

ok@quintus.UUCP (Richard A. O'Keefe) (12/06/87)

In article <8112@steinmetz.steinmetz.UUCP>, stpeters@dawn.steinmetz
(Dick St.Peters) wrote:
> In article <6793@brl-smoke.ARPA> gwyn@brl.arpa
> (Doug Gwyn (VLD/VMB) <gwyn>) writes:
> >In article <14107@oddjob.UChicago.EDU> matt@oddjob.uchicago.edu
> > (Java Man) writes:
> >>o 204% dd if=g*
> >>o 205% set if=g*
> 	[deleted]
> >All this shows is that "dd" ought to be fixed and the Cshell should
> >be stamped out..
> 
> Hell, no!  "Fixing" dd would break an awful lot of scripts, and it's

Fixing dd needn't involve breaking anything.
Last night, as an exercise in sh(1) programming, I wrote a script
	convert-and-copy
which takes arguments like  "-o output" rather than "ofs=output".
It also checks the arguments somewhat more thoroughly than dd.
Total time: 1/2hr to write the script, 1/2hr to debug it.
Result: no scripts are broken, and I have a dd I can live with.
By the way, there is a way to suppress file-name expansion in sh(1):
	set -f
My script has the form
	<big comment printed out by convert-and-copy -help>
	<parse arguments>
	set -f
	dd <converted arguments>
So	
	convert-and-copy -i '*.ebc' -t ascii -o '?.asc'
works just fine.

Concerning "set if=g*"; it is not the case that sh(1) gets this
right, rather that it doesn't do what you might expect.  Suppose
you have a directory containing "g=gx" and "g=gx.c", and you type
	$ g=g*
	$ echo $g
You see the output
	g=gx g=gx.c
and think, ah, g="g=gx g=gx.c" just as I expected, and file-name
expansion is done to the bit after the "=".  Wrong.  Try
	$ echo "$g"
and you see the output
	g*
Now the sh(1) manual page (and the SVID) explicitly say that
"filename generation" is not done if the apparent pattern doesn't
match anything, and it does NOT say that there is anything special
about "=".  So another expectation might be that
	$ g=g*
would expand into "g=gx g=gx.c" and then bind g to gx or to gx.c.
I have experimented with this a bit, and it seems that the rule is
	if a word contains an "=" and either
	the "-k" option is set, or the word does not follow a command
	then the word will not be subject to filename generation.
No doubt this is explained somewhere, but I cannot find it in the SVID.
If you want expansion done in the right hand side of a definition,
you have to use
	$ g=`echo g*`
which has its own complications, because some bright helpful person
decided that the System V echo command should interpret "\", and
thought this clever feature was so wonderful that there should be
no way to switch it off.  (Now I know why they call it Missed'em V.)
System's V "echo" is now great for printing messages, but useless
for use in situations like this.  I now have my own program for
echoing.  I just wish AT&T would follow their own rules...

rbj@icst-cmr.arpa (Root Boy Jim) (12/11/87)

   > >>o 204% dd if=g*

I used to use "if=" and "of=" until I RTFM. Seems `dd' uses stdin and stdout
by default. Now I type `dd<rhp0a>rhp1a bs=16k' instead of the brutally
long sequence `dd if=rhp0a of=rhp0a bs=16k'. Just think, that's eight
characters saved I can spend flaming at y'all instead!

	(Root Boy) Jim Cottrell	<rbj@icst-cmr.arpa>
	National Bureau of Standards
	Flamer's Hotline: (301) 975-5688
Our father who art in heaven..  I sincerely pray that SOMEBODY
 at this table will PAY for my SHREDDED WHAT and ENGLISH MUFFIN..
 and also leave a GENEROUS TIP...