echo foo > a b does not error

2011-05-12 Thread Petteri Räty
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: i686-pc-linux-gnu-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib  
-DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
 -DSTANDARD_UTILS_PATH='/bin:/usr/bin:/sbin:/usr/sbin' 
-DSYS_BASHRC='/etc/bash/bashrc' -DSYS_BASH_LOGOUT='/etc/bash/bash_logout' 
-DNON_INTERACTIVE_LOGIN_SHELLS -DSSH_SOURCE_BASHRC -O2 -march=native -pipe 
-fomit-frame-pointer
uname output: Linux pena 2.6.38-gentoo #1 SMP Wed Mar 23 00:19:18 EET 2011 i686 
Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz GenuineIntel GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 4.2
Patch Level: 10
Release Status: release

Description:
man bash says the redirection target can only be a single word but
bash seems to silently ignore multiple words when no expansions happen

Repeat-By:
betelgeuse@pena ~/test $ echo foo > a b
betelgeuse@pena ~/test $ multi="a b"
betelgeuse@pena ~/test $ echo foo > ${multi}
bash: ${multi}: ambiguous redirect

Fix:
I think both cases should give the same error



Re: echo foo > a b does not error

2011-05-12 Thread Greg Wooledge
On Thu, May 12, 2011 at 03:13:51PM +0300, Petteri Räty wrote:
> Repeat-By:
>   betelgeuse@pena ~/test $ echo foo > a b

This one is not an error; it simply does not mean what you think it means.
The following commands are all equivalent:

echo foo > a b
echo > a foo b
> a echo foo b
echo foo b > a

In a simple command, the redirection is allowed to appear *anywhere*,
including in between arguments.

>   betelgeuse@pena ~/test $ multi="a b"
>   betelgeuse@pena ~/test $ echo foo > ${multi}
>   bash: ${multi}: ambiguous redirect

This one is different, because the redirection is parsed before
parameter expansion.  If you have a filename in a variable, and you want
to redirect to that filename, always quote it:

echo foo > "$multi"

Always.



Re: echo foo > a b does not error

2011-05-12 Thread Andreas Schwab
Petteri RXXty  writes:

>   betelgeuse@pena ~/test $ echo foo > a b

This is the same as: echo foo b > a

Andreas.

-- 
Andreas Schwab, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: echo foo > a b does not error

2011-05-12 Thread Petteri Räty
On 05/12/2011 03:35 PM, Andreas Schwab wrote:
> Petteri RXXty  writes:
> 
>>  betelgeuse@pena ~/test $ echo foo > a b
> 
> This is the same as: echo foo b > a
> 
> Andreas.
> 

Sorry about the noise. With that hint found out the relevant documentation.

Petteri



signature.asc
Description: OpenPGP digital signature