[comp.unix.shell] Wierd shell bug could be useful

gwyn@smoke.brl.mil (Doug Gwyn) (01/31/91)

In article <618@tndsyd.oz> root@tndsyd.oz (the main man) writes:
>Try this out:
>	$ echo > foo '
>	> garbage
>	> '
>A user friendly bug !!!

What do you mean, bug?  The Bourne shell has always been advertised
as accepting I/O redirections anywhere among the arguments.

Harald.Eikrem@elab-runit.sintef.no (01/31/91)

said root@tndsyd.oz    [which is no valid internet mail address --H.E]:

> Try this out:
> 	$ echo > foo '
> 	> garbage
> 	> ...
> 	> ...
> 	> ...
> 	> ...
> 	> '
> 	$
> 
> Then cat foo. This is a wierd bug but could be used instead of:
> 	cat << ! > foo
> 	garbage
> 	...
> 	...
> 	...
> 	...
> 	!
> 
> A user friendly bug !!!

What do you mean is a bug here?  This behaves perfecly normal to me, and of
course the two methods produce different results.

$ echo > foo '
> bar
> and
> grill
> '
$ cat foo    

bar
and
grill

$ cat << ! > foo
> bar
> and
> grill
> !
$ cat foo
bar
and
grill
$ 


--Harald E

sef@kithrup.COM (Sean Eric Fagan) (01/31/91)

In article <618@tndsyd.oz> root@tndsyd.oz (the main man) writes:
>Try this out:
>	$ echo > foo '
>	> garbage
>	> '

Uhm, why do you consider this a bug?  That's doing exactly what I would
expect it to.

-- 
Sean Eric Fagan  | "I made the universe, but please don't blame me for it;
sef@kithrup.COM  |  I had a bellyache at the time."
-----------------+           -- The Turtle (Stephen King, _It_)
Any opinions expressed are my own, and generally unpopular with others.

dws@margay.cs.wisc.edu (DaviD W. Sanderson) (01/31/91)

In article <618@tndsyd.oz> root@tndsyd.oz (the main man) writes:
>Try this out:
>	$ echo > foo '
>	> garbage
>	> ...
>	> '
[...]
>A user friendly bug !!!

It isn't a bug.  The shell allows i/o redirections to occur anywhere on
the command line (it even says so in the man page), and it also allows
multiline quoted strings.  So the example you gave was simply an echo
of a single quoted string redirected into a file.  Putting the
redirection in the middle is unusual but perfectly legal.  You could
equally well have given

	$ > foo echo '		or	$ echo '
	junk				junk
	'				' > foo

Note that if you substitute "cat" for "echo" you will get an error from
cat because presumably cat will not be able to find a file whose name
is given by the multiline quoted string.  Unless you like pathological
file names! :-)
-- 
       ___
      / __\  U N S H I N E	           DaviD W. Sanderson
     |  |  | I N E			    dws@cs.wisc.edu
_____|  |  |_____  ________
\      / \   |__/ /////__	Fusion Powered Locomotives Made to Order
 \____/   \__|_/  \\\\\______	 (TARDIS model available at extra cost)

root@tndsyd.oz (the main man) (01/31/91)

Try this out:
	$ echo > foo '
	> garbage
	> ...
	> ...
	> ...
	> ...
	> '
	$

Then cat foo. This is a wierd bug but could be used instead of:
	cat << ! > foo
	garbage
	...
	...
	...
	...
	!

A user friendly bug !!!

jeff@onion.rain.com (Jeff Beadles) (02/02/91)

In article <618@tndsyd.oz> root@tndsyd.oz (the main man) writes:
>Try this out:
>	$ echo > foo '
>	> garbage
>	> '
>	$

This is not a bug!  I often write scripts with something like this:

$ < file program > file2

The shell will allow redirection operators ('<' and '>') most anywhere.

It's not a bug, it's a FEATURE! :-)


	-Jeff
-- 
Jeff Beadles		jeff@onion.rain.com