Feature: disallow |

2015-03-18 Thread Ed Avis
In bash, the empty command can be redirected to a file:

% out

It will create or overwrite 'out' as the empty file.  That may be useful.
But somehow you can also say

% whoami | out

This again writes empty content.  I suggest this odd feature is not useful and 
indeed gets in the way,
since when making pipelines you may mistakenly put an extra | at the last step 
before the output redirection.

Bash should forbid the odd syntax with | immediately followed by .
If you have | it must be followed by a command.  Note that in most cases this 
is already required:

% | # syntax error
% whoami | # syntax error

-- 
Ed Avis e...@waniasset.com


__
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
__



Re: Feature: disallow |

2015-03-18 Thread Andreas Schwab
Ed Avis e...@waniasset.com writes:

 If |  is a valid construct, what are its semantics?

$ whoami | out tr 'a 'b'

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
And now for something completely different.



Re: Feature: disallow |

2015-03-18 Thread Dan Douglas
On Tue, Mar 17, 2015 at 11:40 AM, Ed Avis e...@waniasset.com wrote:
 In bash, the empty command can be redirected to a file:

 % out

 It will create or overwrite 'out' as the empty file.  That may be useful.
 But somehow you can also say

 % whoami | out

This isn't surprising or deserving of a special case treatment. It's a
valid permutation that I would expect to work as required.

This isn't even close to the most likely way one might screw up a
redirect. Forgetting a quote or escape in a non-obvious place such as
within an assignment or argument to a command is far more likely to
bite you. Examples:

var=fooout
let x5\?y:z

If you're worried about making a mistake, enable the noclobber option
in your bashrc.

-- 
Dan Douglas



RE: Feature: disallow |

2015-03-18 Thread Ed Avis
The reason I found 'whoami | out' to be surprising is that none of the 
following work:

% | out
% (whoami |)
% whoami | | cat

If |  is a valid construct, what are its semantics?

-- 
Ed Avis e...@waniasset.com

__
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
__


RE: Feature: disallow |

2015-03-18 Thread Ed Avis
Thanks.  So 'whoami | out' working is a natural consequence of the fact that 
'out' is a command by itself.
IMHO it would have been better for the Unix shell to forbid that, and require 
': out' if you really do want to run the null command and redirect its output, 
but it's too late now.

-- 
Ed Avis e...@waniasset.com

__
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
__



Re: Feature: disallow |

2015-03-18 Thread Bob Proulx
Ed Avis wrote:
 Thanks.  So 'whoami | out' working is a natural consequence of the
 fact that 'out' is a command by itself.

It is a natural consequence of parsing redirections before parsing
commands.  The redirection happens before the command execution and an
empty command is valid.  That redirections happen in an earlier pass
across the command line is why they can occur anywhere in the command.
By convention we put rediections at the end.  But they can also
validly occur first (as the previous example showed) or in the middle.

 IMHO it would have been better for the Unix shell to forbid that,
 and require ': out' if you really do want to run the null command
 and redirect its output, but it's too late now.

If it did then it would be incompatible with all of the rest that
allow it.  As I recall one of the obscure fringe Unix lookalike
systems did exactly that in their shell.  I forget details now.  But
because of that some of us do always use : instead of an empty
redirection simply due to it.

Bob