`if $(cmd);' is a positive when there's no output from cmd

2006-04-15 Thread Herculano Einloft
Hey all, 

$ if $(echo string >/dev/null); then echo true; fi 
true 

This should be a syntax error, since 

$ if; then echo true; fi 
bash: syntax error near unexpected token `;' 

Tested on 

GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu) 
Copyright (C) 2002 Free Software Foundation, Inc. 

and 

GNU bash, version 3.1.7(1)-release (i386-redhat-linux-gnu) 
Copyright (C) 2005 Free Software Foundation, Inc. 

Regards 


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: `if $(cmd);' is a positive when there's no output from cmd

2006-04-15 Thread Herculano Einloft
Em (02:25:11), Andreas Schwab escreveu: 

> 
>> Hey all, 
>> 
>> $ if $(echo string >/dev/null); then echo true; fi 
>> true 
>> 
>> This should be a syntax error 
> 
>No, it is a perfectly valid command, syntactically. That the command 
>substitution expands to nothing has no significance any more once the 
>command is parsed, just like shell meta characters resulting from 
>expansions are taken literally. 
> 
>Andreas. 

That's not true.. try: 

$ echo $(echo \*) 

or 

$ a=*; echo "$a"; echo $a 

for illustration. 

Regards 


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: `if $(cmd);' is a positive when there's no output from cmd

2006-04-15 Thread Herculano Einloft
Em (21:43:32), Mike Frysinger escreveu: 

>On Saturday 15 April 2006 19:55, Herculano Einloft wrote: 
>> $ if $(echo string >/dev/null); then echo true; fi 
>> true 
>> 
>> This should be a syntax error, since 
>> 
>> $ if; then echo true; fi 
>> bash: syntax error near unexpected token `;' 
> 
>the first command statement is more like: 
>if :; then echo true; fi 
>-mike 

Hey mike.. 

Care to explain that? I still see a difference between 

$ if $(echo :); then echo true; fi 

which would be your example, and 

$ if $(:); then echo true; fi 

which would be mine 

Regards 


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash


Re: `if $(cmd);' is a positive when there's no output from cmd

2006-04-15 Thread Herculano Einloft
Em (02:25:11), Andreas Schwab escreveu: 


>Herculano Einloft writes: 
> 
>> Hey all, 
>> 
>> $ if $(echo string >/dev/null); then echo true; fi 
>> true 
>> 
>> This should be a syntax error 
> 
>No, it is a perfectly valid command, syntactically. That the command 
>substitution expands to nothing has no significance any more once the 
>command is parsed, just like shell meta characters resulting from 
>expansions are taken literally. 
> 
>Andreas. 
> 

Anyway, I see your point. It can't be a syntax error, since 
of course it parses correctly. 

It's kind of a weird case though, but I guess that's it. 

Thanks all 


___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash